qq空间自动发垃圾说说里发什么说说

幽默的说说
【 liuxue86.com - 实用资料 】
  公司上,我自告奋勇表演了诗朗诵。读到&昔人已乘去,此地空余楼。&的时候,老板问道:&黄鹤哪去了?&我冷笑一声,答道:&王八蛋老板黄鹤不发奖金带着小姨子跑了。&
  烟对身体不好,特别是肺。老烟民都知道,几年之后,肺会发黑,灰化肥也会发黑。
  就刚才,我一个同事跟我说,电影家乐福海盗挺不错的。瞬间笑疯,啥家乐福海盗啊,还沃尔玛海盗呢
  圣诞老人用哪家快递?这么多年了都没收到,差评。。。
  你们还有没有啊,居然连是哪三国都不知道,东汉末年分三国,烽火,连天和不休
  我觉得可以拿诺基亚原声铃声唱这句&一个傻逼,拿着手机,发着短信息&
  事证实明当你看这完信条息之后才发字现都乱是的
  今年决定好好投资理财。看了不少的项目,目前觉得比较靠谱的是:余额宝里存两万,每天赚两块钱利息买注彩票。
  沟通请好好说话,大家都不熟谁认识谁啊,总是一副自以为了解对方的样子说不搭边的话,只会让人觉得你有病。
  昨晚失眠躺床上玩Pad把自己砸晕了,现在刚刚苏醒。。。
  如何在公交车上抢到座位:1,找一个睡着的人;2,轻轻的叫醒他;3,告诉他该下车了。 嗯,我现在在想哪个王八蛋叫我下的车,呵呵。
  我不管,你看了我的,就是我的人了
  刚出来散步,被歹徒劫钱,歹徒拿着刀对我喊「你敢动一下试试?」我当时就不乐意了,妈个鸡你抢劫我就算了,凭啥还让我感动。
  我这个人对美食挺讲究的,一间餐厅只要没有wifi我肯定扭头就走。
  故意起得比闹钟早,想给它一个下马威。
  上联:说实话办实事一身正气,下联:不贪污不受贿两袖清风 求横批?答:查无此人
  &今晚我要裸睡!&--150只蚊子点了赞。
  刚才路过肯德基,里面排着好几趟长队,就为了买个半价的全家桶,呵呵,我才不会为了吃而排队等半天,因为我根本拿不出四十五块五。
  我想吃月饼,没有月饼可以吃!!!就喜欢吃月饼啊~~~五仁,韭菜,腐乳月饼我都可以接受的啊~~~~~
  怎样才能做到不在乎别人骂?生活中或多或少会有被人骂的时候,怎样才能做到不在乎别人的谩骂?我觉得最重要的是要学会懂得替别人考虑,换位思考。不能只顾及自己的情绪。这是一个内心强大的人的必修课。我每次被别人骂,被别人喷,都会站在他的角度想,他是不是脑袋被门挤啦,他是不是被狗咬啦,他是不是昨天晚上房子被人烧了,人要有一颗包容的心。。。
  想了解更多实用资料网的资讯,请访问:
本文来源:
不但还造句【一】1、要取得好成绩,不但要用功,还要改进学习方法。2、我们不但要努力学习文化科学知识,还要注意培养自己高尚的道德品质。3、他不但自己学习好,而且还能帮助别人。4、你不
不但而且造句【一】(1)小明不但学习成绩好,而且也很勤劳。(2)蒋老师的教学很有特色,不但讲得深入浅出,而且还注意因材施教,调动每一个学生的学习积极性。(3)你不但很懒,而且很狡猾
妈妈们在宝宝睡之前给他们讲故事,可以让孩子们了解更多的知识。以下是出国留学网小编为大家精心准备的“睡前故事《傲慢的小马》”,欢迎大家阅读,仅供大家参考,希望对您有所帮助。更多睡前故
青蛙是大家都喜欢的,有哪些关于青蛙的睡前故事呢?以下是出国留学网小编为大家精心准备的“《青蛙大侠》睡前故事”,欢迎大家阅读,仅供大家参考,希望对您有所帮助。更多睡前故事在出国留学网
在宝宝睡觉之前给他们讲讲故事是一个不错的选择。以下是出国留学网小编为大家精心准备的“睡前故事《圣诞老人传说》”,欢迎大家阅读,仅供大家参考,希望对您有所帮助。更多睡前故事在出国留学1.在文本域中输入文字(可以不添加)
2.点击添加图片(可以不添加)
3.点击发表
4.发表成功,文字和图片是超链接,点击就可以查看全部内容
5.点击图片查看原图,没有图片则不显示查看原图的超链接
主要用到的知识有:
图片的上传,session,JavaScript
主要思路:图片上传到服务器,获得图片的名字,就可以用img标签来显示,src就可以有路径了,文字保存在session,获得即可
代码随后上传
添加文字图片
点击发表后的页面
任意点击图片或者文字,查看全文
&fileupload.jsp
&%@ page language="java" contentType="text/ charset=UTF-8"
import="java.util.*" pageEncoding="UTF-8"%&
&%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&Insert title here&/title&
&link rel="stylesheet" href="../css/fileupload.css"&
&div class="title_img"&
&img src="../images/send_message.png" /&
&div class="message_main_div"&
&form action="../upload" method="post" enctype="multipart/form-data"&
&textarea id="text" cols="65" rows="18" name="message"&&/textarea&
&hr class="hr14"&
&a href="javascript:;" class="file"&添加图片 &input type="file"
name="file1" id=""
accept=".jpg,bmp,.gig,.png,.tif,.rgb,.dib,.eps,.jpe,.pcx,.bmp,.gif"&
&hr class="hr14"&
&input type="submit" class="btn-style-03" value="发表" /&
UploadServlet.java
import java.io.IOE
import java.io.OutputStreamW
import java.io.UnsupportedEncodingE
import javax.servlet.ServletC
import javax.servlet.ServletE
import javax.servlet.annotation.MultipartC
import javax.servlet.annotation.WebInitP
import javax.servlet.annotation.WebS
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import javax.servlet.http.P
import com.auuzee.dao.MessageD
import com.auuzee.dao.UserD
import com.auuzee.dbutil.DBU
import com.auuzee.entity.U
import java.io.F
import java.io.FileNotFoundE
import java.io.FileOutputS
@WebServlet(urlPatterns = { "/upload" }, initParams = { @WebInitParam(name = "savePath", value = "upload") })
@MultipartConfig
public class UploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
// 上传文件的保存路径
String savePath = null;
MessageDao md = new MessageDao();
UserDao ud = new UserDao();
public UploadServlet() {
public void init(ServletConfig config) throws ServletException {
// 获取上传文件的保存路径
savePath = config.getInitParameter("savePath");
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
User user1 = new User();
user1 = (User) request.getSession().getAttribute("user");
String userName = user1.getUserName();
String theLastImg = "";
String dbImg = "";
request.setCharacterEncoding("utf-8");
String message = request.getParameter("message");
if (message == null || "".equals(message) || message.trim() == null) {
message = null;
// 进行文本处理
String s1 = "\n";
if (message.contains("\n")) {
message = message.replaceAll(s1, "&br&");
String fileName = null;
// 获得页面封装的Part对象
Part part = request.getPart("file1");
// 获得请求头(包含了文件名)
String header = part.getHeader("content-disposition");
// 从请求头中获得文件名
fileName = getFileName(header);
// System.out.println("fileName是" + fileName + "啥");
if ("".equals(fileName) || fileName == null || fileName == "") {
System.out.println("fileName文件名是null");
System.out.println("fileName文件名不是null");
if (fileName.endsWith(".jpg") || fileName.endsWith(".bmp") || fileName.endsWith(".gig")
|| fileName.endsWith(".png") || fileName.endsWith(".tif") || fileName.endsWith(".rgb")
|| fileName.endsWith(".dib") || fileName.endsWith(".eps") || fileName.endsWith(".jpe")
|| fileName.endsWith(".pcx") || fileName.endsWith(".bmp") || fileName.endsWith(".gif")) {
// 获得服务器存储上传文件的真实路径
String realSavePath = request.getServletContext().getRealPath(savePath);
System.out.println("realSavePath:" + realSavePath);
// 向服务器保存路径上传文件
// 在upload下面以用户的名字建立文件夹,
String imgFile = realSavePath + "/" + userN
System.out.println(imgFile);
File newFolder = new File(imgFile);
if (!newFolder.exists() && !newFolder.isDirectory()) {
System.out.println("//图片文件夹不存在");
newFolder.mkdir();
System.out.println("//图片文件夹存在");
dbImg = userName + "_" + System.currentTimeMillis() + "_" + fileN
theLastImg = imgFile + "/" + dbI
dbImg = "upload" + "/" + userName + "/" + dbI
System.out.println("图片的最终路径是:" + theLastImg);
part.write(theLastImg);
request.getSession().setAttribute("message", message);
// 为每个用户的用户名设置文件夹
String targetFileName = "C:/Users/p8780/Desktop/file/file/" + userN
File newFileName = new File(targetFileName);
if (!newFileName.exists() && !newFileName.isDirectory()) {
System.out.println("//不存在");
newFileName.mkdir();
System.out.println("//目录存在");
// 在这个用户文件夹下生成txt文件,文件名字为当前时间戳
String targetT
if (message != null) {
targetTxt = targetFileName + "/" + userName + System.currentTimeMillis() + ".txt";
File file1 = new File(targetTxt);
if (!file1.exists()) {
file1.createNewFile();
} catch (IOException e) {
targetTxt = null;
String str =
fileCopyByStreamArray(str, targetTxt);
// 通过用户名查询用户的Id;
int userId = ud.selectUserId(userName);
// 把文本文件的名字,和图片的名字保存在数据库中
md.addMessage(targetTxt, dbImg, userId);
request.getSession().setAttribute("realSavePath", fileName);
response.sendRedirect("jsp/userlist.jsp");
* request.getRequestDispatcher("jsp/userlist.jsp").forward(request,
* response);
@SuppressWarnings("unused")
public static void fileCopyByStreamArray(String str, String targetFile)
throws UnsupportedEncodingException, FileNotFoundException {
System.out.println("正在写文件....");
FileOutputStream fos = null;
OutputStreamWriter osw = null;
File file1 = new File(targetFile);
fos = new FileOutputStream(file1);
osw = new OutputStreamWriter(fos, "UTF-8");
byte[] b = new byte[1000];
b = str.getBytes();
int length = b.
fos.write(b, 0, length);
fos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
fos.close();
} catch (IOException e) {
e.printStackTrace();
// 通过请求头解析文件名
private String getFileName(String header) {
System.out.println("header:" + header);
// header:form- name="file1";
// filename="D:\Document And Settings2\hpe\Desktop\servletapi.zip"
String[] tmp1 = header.split(";");
String[] tmp2 = tmp1[2].split("=");
String fileName = tmp2[1].substring(tmp2[1].lastIndexOf("\\") + 1).replaceAll("\"", "");
System.out.println("fileName:" + fileName + "接受");
if (fileName == null || fileName == "") {
System.out.println("fileName是null");
return fileN
fileupload.css
margin: 0;
padding: 0;
font: 12px
Verdana, Arial, Geneva, sans-
color: #404040;
background-color:#
background: url(../images/send_bg.jpg) no-
background-size:
.message_main_div {
margin: 20
width: 384
display: inline-
background: #FCFCFC;
border: 1px solid #99D3F5;
border-radius: 4
padding: 4px 12
color: #1E88C7;
text-decoration:
text-indent: 0;
line-height: 20
.file input {
font-size: 100
opacity: 0;
.file:hover {
text-decoration:
.btn-style-03 {
border-style:
padding: 8px 30
line-height: 24
font: 16px "Microsoft YaHei", Verdana, Geneva, sans-
margin-left: 95%;
.btn-style-03 {
border: 1px #029e4f
-webkit-box-shadow: inset 0px 0px 1px #
-moz-box-shadow: inset 0px 0px 1px #
box-shadow: inset 0px 0px 1px #
-webkit-border-radius: 4
-moz-border-radius: 4
border-radius: 4
text-shadow: 1px 1px 0px #45a1d6;
background-color: #0fda74;
background-image: -webkit-gradient(linear, 0 0%, 0 100%, from(#0fda74),
to(#05c263));
background-image: -webkit-linear-gradient(top, #0fda74 0%, #05c263 100%);
background-image: -moz-linear-gradient(top, #0fda74 0%, #05c263 100%);
background-image: -ms-linear-gradient(top, #0fda74 0%, #05c263 100%);
background-image: -o-linear-gradient(top, #0fda74 0%, #05c263 100%);
background-image: linear-gradient(top, #0fda74 0%, #05c263 100%);
.btn-style-03:hover {
background-color: #05c263;
background-image: -webkit-gradient(linear, 0 0%, 0 100%, from(#05c263),
to(#0fda74));
background-image: -webkit-linear-gradient(top, #05c263 0%, #0fda74 100%);
background-image: -moz-linear-gradient(top, #05c263 0%, #0fda74 100%);
background-image: -ms-linear-gradient(top, #05c263 0%, #0fda74 100%);
background-image: -o-linear-gradient(top, #05c263 0%, #0fda74 100%);
background-image: linear-gradient(top, #05c263 0%, #0fda74 100%);
text-decoration:
height: 10
.title_img{
margin-top:60
text-align:
send_message.png
send_bg.jpg
messageDao.java
package com.auuzee.
import com.auuzee.dbutil.DBU
import com.auuzee.entity.M
public class MessageDao {
DBUtil dbu = new DBUtil();
Message ms = new Message();
public int addMessage(String fileName, String imgName, int userId) {
String sql = "insert into message (fileName,imgName,userId,messageTime) values('" + fileName + "','" + imgName
+ "','" + userId
+ "',sysdate )";// 一定要进行格式转换,Mysql中不用
// 调用共通的增删改方法执行sql
int count = dbu.update(sql, null);
dbu.close();
message.java
package com.auuzee.
public class Message {
private String fileN//发表的说说文件
private String imgN//发表的说说图片
private int userId;//用户id
private String messageT//发表时间
private String userN//用户名
private int//浏览数
private int//赞
private int//评论
public int getRemark() {
public void setRemark(int remark) {
this.remark =
public int getLove() {
public void setLove(int love) {
this.love =
public int getCount() {
public void setCount(int count) {
this.count =
public String getUserName() {
return userN
public void setUserName(String userName) {
this.userName = userN
public String getFileName() {
return fileN
public void setFileName(String fileName) {
this.fileName = fileN
public String getImgName() {
return imgN
public void setImgName(String imgName) {
this.imgName = imgN
public int getUserId() {
return userId;
public void setUserId(int userId) {
this.userId = userId;
public String getMessageTime() {
return messageT
public void setMessageTime(String messageTime) {
this.messageTime = messageT
DBUtil里面封装的是数据库的连接配置信息。
&userDao.java
package com.auuzee.
import java.sql.ResultS
import java.sql.SQLE
import java.text.SimpleDateF
import java.util.ArrayL
import java.util.L
import com.auuzee.dbutil.DBU
import com.auuzee.entity.MeU
import com.auuzee.entity.M
import com.auuzee.entity.U
public class UserDao {
DBUtil dbu = new DBUtil();
// 查询所有说说的总记录数
public int selectUsersSize() {
String sql = "select count(*) from message";
ResultSet rs = dbu.select(sql, null);
int size = 0;
while (rs.next()) {
size = rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbu.close();
// 查询纯文本的总记录数
public int selectPlainTextSize() {
String sql = "select count(*) from message where imgName is null";
ResultSet rs = dbu.select(sql, null);
int size = 0;
while (rs.next()) {
size = rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbu.close();
// 查询纯图片的总记录数
public int selectPlainImgsSize() {
String sql = "select count(*) from message where fileName is null";
ResultSet rs = dbu.select(sql, null);
int size = 0;
while (rs.next()) {
size = rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbu.close();
// 查询图文结合的总记录数
public int selectImgTextSize() {
String sql = "select count(*) from message where imgName is not null and fileName is not null";
ResultSet rs = dbu.select(sql, null);
int size = 0;
while (rs.next()) {
size = rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbu.close();
// 通过分页查询所有信息
public List&Message& selectAllMessages(int currentPage, int pageSize) {
String sql = "select * from (select a1.*,rownum rn from"
+ "(select * from message order by messageTime desc) a1 where rownum &=?) where rn&=?";
Object[] param1;
if (currentPage == 1) {
Object[] param = { pageSize, 1 };
Object[] param = { currentPage * pageSize, (currentPage - 1) * pageSize + 1 };
ResultSet rs = dbu.select(sql, param1);
List&Message& messageList = new ArrayList&Message&();
SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while (rs.next()) {
Message message = new Message();
message.setFileName(rs.getString("fileName"));
message.setImgName(rs.getString("imgName"));
message.setMessageTime(myFmt.format(rs.getTimestamp("messageTime")));
message.setUserId(rs.getInt("userId"));
// 得到喜欢和赞的人数
message.setLove(rs.getInt("love"));
message.setRemark(rs.getInt("remark"));
message.setCount(rs.getInt("count") + 1);
String time = rs.getTimestamp("messageTime") + "";
time = time.substring(0, time.length() - 2);
addCount(time, rs.getInt("userId"));
messageList.add(message);
return messageL
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
dbu.close();
// 通过发表时间增加浏览次数
public void addCount(String messageTime, int userId) throws SQLException {
// 查询之前先加1
String sql = "update message set count=count+1 where userId=? and messageTime=to_date(?,'yyyy-mm-dd hh24:mi:ss')";
System.out.println("sql是" + sql);
Object[] param1 = { userId, messageTime };
int count = dbu.update(sql, param1);
if (count & 0) {
System.out.println("数据库中添加一条浏览信息成功");
// 通过分页查询文本信息
public List&Message& selectAllTextMessages(int currentPage, int pageSize) {
String sql = "select * from (select a1.*,rownum rn from"
+ "(select * from message where imgName is null order by messageTime desc) a1 where rownum &=?) where rn&=?";
Object[] param1;
if (currentPage == 1) {
Object[] param = { pageSize, 1 };
Object[] param = { currentPage * pageSize, (currentPage - 1) * pageSize + 1 };
ResultSet rs = dbu.select(sql, param1);
List&Message& messageList = new ArrayList&Message&();
SimpleDateFormat myFmt = new SimpleDateFormat("MM-dd HH:mm:ss");
while (rs.next()) {
Message message = new Message();
message.setFileName(rs.getString("fileName"));
message.setImgName(rs.getString("imgName"));
message.setMessageTime(myFmt.format(rs.getTimestamp("messageTime")));
message.setUserId(rs.getInt("userId"));
message.setCount(rs.getInt("count") + 1);
String time = rs.getTimestamp("messageTime") + "";
time = time.substring(0, time.length() - 2);
addCount(time, rs.getInt("userId"));
messageList.add(message);
return messageL
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
dbu.close();
// 通过分页查询图片信息
public List&Message& selectAllImgsMessages(int currentPage, int pageSize) {
String sql = "select * from (select a1.*,rownum rn from"
+ "(select * from message where fileName is null
order by messageTime desc) a1 where rownum &=?) where rn&=?";
Object[] param1;
if (currentPage == 1) {
Object[] param = { pageSize, 1 };
Object[] param = { currentPage * pageSize, (currentPage - 1) * pageSize + 1 };
ResultSet rs = dbu.select(sql, param1);
List&Message& messageList = new ArrayList&Message&();
SimpleDateFormat myFmt = new SimpleDateFormat("MM-dd HH:mm:ss");
while (rs.next()) {
Message message = new Message();
message.setFileName(rs.getString("fileName"));
message.setImgName(rs.getString("imgName"));
message.setMessageTime(myFmt.format(rs.getTimestamp("messageTime")));
message.setUserId(rs.getInt("userId"));
message.setCount(rs.getInt("count") + 1);
String time = rs.getTimestamp("messageTime") + "";
time = time.substring(0, time.length() - 2);
addCount(time, rs.getInt("userId"));
messageList.add(message);
return messageL
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
dbu.close();
// 通过分页查询图文信息
public List&Message& selectAllTextImgsMessages(int currentPage, int pageSize) {
String sql = "select * from (select a1.*,rownum rn from"
+ "(select * from message where fileName is not null and imgName is not null order by messageTime desc) a1 where rownum &=?) where rn&=?";
Object[] param1;
if (currentPage == 1) {
Object[] param = { pageSize, 1 };
Object[] param = { currentPage * pageSize, (currentPage - 1) * pageSize + 1 };
ResultSet rs = dbu.select(sql, param1);
List&Message& messageList = new ArrayList&Message&();
SimpleDateFormat myFmt = new SimpleDateFormat("MM-dd HH:mm:ss");
while (rs.next()) {
Message message = new Message();
message.setFileName(rs.getString("fileName"));
message.setImgName(rs.getString("imgName"));
message.setMessageTime(myFmt.format(rs.getTimestamp("messageTime")));
message.setUserId(rs.getInt("userId"));
message.setCount(rs.getInt("count") + 1);
String time = rs.getTimestamp("messageTime") + "";
time = time.substring(0, time.length() - 2);
addCount(time, rs.getInt("userId"));
messageList.add(message);
return messageL
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
dbu.close();
// 通过Id查询User表中的基本信息,直接保存在合并的实体类对象中
public void selectUserName(int userId, MeUser mu) {
String sql = "select userName ,age ,sex,titleImg from user6 where userId=?";
Object[] param1 = { userId };
ResultSet rs = dbu.select(sql, param1);
while (rs.next()) {
mu.setUserName(rs.getString("userName"));
mu.setAge(rs.getInt("age"));
mu.setSex(rs.getInt("sex"));
mu.setTitleImg(rs.getInt("titleImg"));
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbu.close();
// 通过userName查询userId
public int selectUserId(String userName) {
String sql = "select userId ,age ,sex from user6 where userName=?";
Object[] param1 = { userName };
ResultSet rs = dbu.select(sql, param1);
int userId = -1;
while (rs.next()) {
userId = rs.getInt("userId");
return userId;
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbu.close();
return userId;
// 用户登录
public User loginCheck(String username, String password) {
String sql = "select * from user6 where userName=? and userPwd=?";
Object[] param = { username, password };
ResultSet rs = dbu.select(sql, param);
User user = null;
while (rs.next()) {
user = new User();
user.setUserId(rs.getInt("userId"));
user.setUserName(rs.getString("userName"));
user.setUserPwd(rs.getString("userPwd"));
user.setAge(rs.getInt("age"));
user.setPwdCommand(rs.getString("pwdCommand"));
user.setSex(rs.getInt("sex"));
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
dbu.close();
// 验证用户名是否存在
public boolean checkUserExists(String userName) {
String sql = "select count(*) from user6 where username=?";
Object[] param = { userName };
ResultSet rs = dbu.select(sql, param);
int count = 0;
while (rs.next()) {
count = rs.getInt(1);
if (count & 0) {
return true;
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
dbu.close();
// 添加用户
public int AddUser(User user) {
String sql = "insert into user6(userId,userName,userPwd,age,pwdCommand,sex,titleImg) values(id_a.nextval,?,?,?,?,?)";
Object[] param = { user.getUserName(), user.getUserPwd(), user.getAge(), user.getPwdCommand(), user.getSex(),
user.getTitleImg() };
int count = dbu.update(sql, param);
dbu.close();
Config.java
package com.auuzee.
import java.io.IOE
import java.util.P
public class Config {
private static Properties pro = new Properties();
// 通过反射的方式加载资源文件
// 只要资源文件和Config类在同一个路径下就能找到并加载到Properties对象中,以map的形式存放
pro.load(Config.class.getResourceAsStream("db.properties"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static final String DBURL = pro.getProperty("DBURL");
public static final String DBIP = pro.getProperty("DBIP");
public static final String DBPORT = pro.getProperty("DBPORT");
public static final String DATABASE = pro.getProperty("DATABASE");
public static final String DBUSER = pro.getProperty("DBUSER");
public static final String DBPASS = pro.getProperty("DBPASS");
public static final String DBDRIVER = pro.getProperty("DBDRIVER");
DBUtil.java
package com.auuzee.
import java.sql.C
import java.sql.DriverM
import java.sql.PreparedS
import java.sql.ResultS
import java.sql.SQLE
import java.sql.S
public class DBUtil {
// 数据库连接字符串
private String url = Config.DBURL + Config.DBIP + Config.DBPORT + Config.DATABASE;
// 数据库连接用户名
private String user = Config.DBUSER;
// 数据库连接密码
private String password = Config.DBPASS;
private Connection con = null;
private PreparedStatement pst = null;
private Statement st = null;
private ResultSet rs = null;
// 获取连接
private void getConn() {
// 加载驱动
Class.forName(Config.DBDRIVER);
// 建立连接
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
* 共通查询方法 params:Strng sql:需要执行的SQL语句 Object[] param:需要替换占位符的参数数组
* return:rs:执行查询得到的结果集
public ResultSet select(String sql, Object[] param) {
// 调用共通方法获取连接
getConn();
// 创建Statement对象
pst = con.prepareStatement(sql);
// SQL占位符替换
if (param != null) {
for (int i = 0; i & param. i++) {
pst.setObject(i + 1, param[i]);
// 执行SQL
rs = pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
* 共通更新方法 params:Strng sql:需要执行的SQL语句 Object[] param:需要替换占位符的参数数组
* return:count:执行更新得到的影响行数
public int update(String sql, Object[] param) {
// 调用共通方法获取连接
getConn();
// 创建Statement对象
pst = con.prepareStatement(sql);
// SQL占位符替换
if (param != null) {
for (int i = 0; i & param. i++) {
pst.setObject(i + 1, param[i]);
// 执行SQL
int count = pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
* 共通批处理方法 params:String[] sql:需要执行的SQL语句数组 return:counts:执行批处理得到的影响行数数组
public int[] batch(String[] sql) {
// 调用共通方法获取连接
getConn();
// 创建Statement对象
st = con.createStatement();
// 添加批处理SQL
for (String s : sql) {
st.addBatch(s);
// 执行批处理
int[] counts = st.executeBatch();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
// 关闭资源
public void close() {
if (rs != null) {
rs.close();
if (st != null) {
st.close();
if (pst != null) {
pst.close();
if (con != null) {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
db.properties
#DBURL=jdbc:mysql://
#DBIP=localhost
#DBPORT=:3306
#DATABASE=/test
#DBUSER=root
#DBPASS=123456
#DBDRIVER=com.mysql.jdbc.Driver
DBURL=jdbc:oracle:thin:@
DBIP=localhost
DBPORT=:1521
DATABASE=:ORCL
DBUSER=system
DBPASS=123456
DBDRIVER=oracle.jdbc.driver.OracleDriver
阅读(...) 评论()

我要回帖

更多关于 qq空间发不了说说 的文章

 

随机推荐