qq空间发视频格式怎样分格发说说

经验5519 米
在线时间98 小时
版本7.11.23
机型小米手机5
签到次数72
MIUI版本7.11.23
{uin:10000,nick:你想说的话,who:1,a uto:1}
大家明白了吧
分享到微信朋友圈
打开微信,点击底部的“发现”,使用 “扫一扫” 即可将网页分享到我的朋友圈。
在线时间5 小时
版本V7.0.5.0.KXDCNCI
积分 14, 距离下一级还需 36 积分
积分 14, 距离下一级还需 36 积分
机型小米手机3/4 WCDMA版
MIUI版本V7.0.5.0.KXDCNCI
经验6032 米
在线时间49 小时
版本7.9.28
机型小米手机5
签到次数136
MIUI版本7.9.28
经验4870 米
在线时间44 小时
版本4.12.5
积分 5035, 距离下一级还需 14965 积分
积分 5035, 距离下一级还需 14965 积分
机型小米手机2A
签到次数78
MIUI版本4.12.5
看看,感谢分享!
经验303 米
在线时间98 小时
版本20.4.7
积分 469, 距离下一级还需 31 积分
积分 469, 距离下一级还需 31 积分
机型小米Note 移动4G/联通4G
签到次数19
MIUI版本20.4.7
够屌!!可是好友在聊天界面可以看到
S-001.jpg (117.3 KB, 下载次数: 0)
经验1275 米
在线时间7 小时
版本7.1.20
积分 1290, 距离下一级还需 710 积分
积分 1290, 距离下一级还需 710 积分
机型小米手机3/4 WCDMA版
签到次数40
MIUI版本7.1.20
经验290 米
在线时间4 小时
版本6.5.26
积分 294, 距离下一级还需 206 积分
积分 294, 距离下一级还需 206 积分
机型IUNI U2
MIUI版本6.5.26
经验1592 米
在线时间7 小时
版本7.3.30
积分 1662, 距离下一级还需 338 积分
积分 1662, 距离下一级还需 338 积分
机型小米手机5SPlus
签到次数111
MIUI版本7.3.30
经验507 米
在线时间11 小时
版本7.6.14
积分 564, 距离下一级还需 1436 积分
积分 564, 距离下一级还需 1436 积分
机型小米手机4 电信4G版
签到次数29
MIUI版本7.6.14
经验156 米
在线时间6 小时
积分 165, 距离下一级还需 35 积分
积分 165, 距离下一级还需 35 积分
机型小米手机3/4 WCDMA版
签到次数10
MIUI版本6.9.1
MIUI七夕鹊桥勋章
MIUI七周年
MIUI 9纪念勋章
万圣节勋章
参加回帖活动
米兔月饼勋章
参加回帖活动
参与红米Note 4X活动
小火箭勋章
神舟11号 话题活动
MIUI五周年
MIUI五周年纪念勋章
已关注微信
MIUI六周年
MIUI六周年纪念勋章
2017年小金鸡勋章
回复2016年度评选活动贴
APP 1000万
MIUI论坛APP注册用户突破1000万纪念勋章
MIUI 300周
MIUI 300周更新纪念勋章
MIUI 7纪念勋章
已关注极客秀微信
关注腾讯微博
已关注腾讯微博
关注新浪微博
已关注新浪微博
为奥运加油勋章
为奥运加油勋章
Copyright (C) 2017 MIUI
京ICP备号 | 京公网安备34号 | 京ICP证110507号qq空间说说如何像诗歌那样排列_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
qq空间说说如何像诗歌那样排列
QQ空间发表说说弄成诗文形式的步骤如下:1、登录手机QQ之后,选择“动态”并点击好友动态进入QQ空间;2、来到手机QQ空间页面,点击“说说”,然后选择“写说说”;3、来到写说说页面,写好标题,再点击键盘中的“回车键”进到下一行,写好第一句诗词的时候,再点回车键切换到下一行,这样每写完一句再按回车键切换,直到诗文形式的说说写好之后,再点击右上角的“发表”即可。
采纳率:96%
来自团队:
写好标题,再点击键盘中的“回车键”进到下一行,写好第一句诗词的时候、来到写说说页面QQ空间发表说说弄成诗文形式的步骤如下:1、登录手机QQ之后,选择“动态”并点击好友动态进入QQ空间,然后选择“写说说”、来到手机QQ空间页面,点击“说说”,再点回车键切换到下一行;3;2
爱情伤感文章,情感文章,心情短语,伤感日志,心情日志,经典语录,唯美伤感的句子,伤心优美的句子,悲伤忧伤语句,QQ空间说说,日记大全,感人的话,英语,名言,非主流,诗词!
用电脑直接复制不就好了
望采纳、、
其他1条回答
为您推荐:
其他类似问题
您可能关注的内容
qq空间的相关知识
换一换
回答问题,赢新手礼包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="/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空间发不了说说 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信