資源簡介
有如下功能:用戶注冊,登錄,用戶信息修改,簽寫留言,留言查看和回復留言功能等。

代碼片段和文件信息
package?db;
import?java.sql.*;
import?java.util.ArrayList;
import?model.LyTable;
import?model.User;
public?class?DB?{
private?String?driverStr=“com.mysql.jdbc.Driver“;
private?String?connStr=“jdbc:mysql://localhost:3306/sa?characterEncoding=gb2312“;
????private?String?dbusername=“root“;
????private?String?dbpassword=“222“;?
????private?Connection?conn=null;
????private?PreparedStatement?pstmt=null;
//?在構造函數中建立與數據庫的連接,這樣在建立DB對象的時候就連接了數據庫
public?DB(){
try?{
Class.forName(driverStr);
conn?=?DriverManager.getConnection(connStr
dbusername?dbpassword);
}?catch?(Exception?e)?{
System.out.println(“無法同數據庫建立連接!“?+?e.toString());
}
}
//?根據username和password查詢用戶,查到就返回該對象,沒有就返回null
public?User?checkUser(String?usernameString?password){
try{
pstmt=conn.prepareStatement(“select?*?from?userTable?where?username=??and?password=?“);
pstmt.setString(1?username);
pstmt.setString(2?password);
ResultSet?rs=pstmt.executeQuery();
User?user=new?User();
while(rs.next()){
user.setId(rs.getInt(1));
user.setUsername(rs.getString(2));
user.setPassword(rs.getString(3));
return?user;
}
return?null;
}catch(Exception?e){
e.printStackTrace();
return?null;
}
}
//?查詢留言信息,返回一個ArrayList
public?ArrayList?findLyInfo(){
try{
ArrayList?al=new?ArrayList();
pstmt=conn.prepareStatement(“select?*?from?lyTable“);
ResultSet?rs=pstmt.executeQuery();
// while(rs.next()){
// System.out.println(rs.getInt(1));
// System.out.println(rs.getInt(2));
// System.out.println(rs.getDate(3));
// System.out.println(rs.getString(4));
// System.out.println(rs.getString(5));
// }
while(rs.next()){
LyTable?ly=new?LyTable();
ly.setId(rs.getInt(1));
ly.setUserId(rs.getInt(2));
ly.setDate(rs.getDate(3));
ly.settitle(rs.getString(4));
ly.setContent(rs.getString(5));
al.add(ly);
}
return?al;
}catch(Exception?e){
e.printStackTrace();
return?null;
}
}
public?String?getUserName(int?id){
String?username?=?null;
try{
pstmt?=?conn.prepareStatement(“select?username?from?userTable?where?id?=??“);
pstmt.setInt(1?id);
ResultSet?rs?=?pstmt.executeQuery();
while(rs.next()){
?username=rs.getString(1);
}
return?username;
}catch(Exception?e){
e.printStackTrace();
return?null;
}
}
public?boolean?insertUser(String?usernameString?pwd){
try{
pstmt=conn.prepareStatement(“insert?into?userTable(usernamepassword)?values(??)“);
pstmt.setString(1?username);
pstmt.setString(2?pwd);
pstmt.executeUpdate();
return?true;
}catch(Exception?e){
e.printStackTrace();
return?false;
}
}
public?boolean?addInfo(LyTable?ly){
try{
pstmt=conn.prepareStatement(“insert?into?lyTable(userIddatetitlecontent)?values(????)“);
pstmt.setInt(1?ly.getUserId());
pstmt.setDate(2?ly.getDate());
pstmt.setString(3
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-06-09?09:59??ly\
?????文件?????????525??2013-05-30?17:04??ly\.classpath
?????目錄???????????0??2013-06-09?10:00??ly\.myeclipse\
?????文件?????????280??2013-05-29?09:14??ly\.myme
?????文件??????????66??2013-06-01?22:55??ly\.myumldata
?????文件????????1220??2013-05-27?11:23??ly\.project
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\me
?????文件??????????39??2013-05-27?11:23??ly\WebRoot\me
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\WEB-INF\
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\WEB-INF\classes\
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\WEB-INF\classes\db\
?????文件????????4024??2013-06-01?23:40??ly\WebRoot\WEB-INF\classes\db\DB.class
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\WEB-INF\classes\model\
?????文件????????1324??2013-05-30?17:04??ly\WebRoot\WEB-INF\classes\model\LyTable.class
?????文件?????????898??2013-05-30?17:04??ly\WebRoot\WEB-INF\classes\model\User.class
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\WEB-INF\classes\servlet\
?????文件????????1851??2013-06-01?23:35??ly\WebRoot\WEB-INF\classes\servlet\AddServlet.class
?????文件????????1871??2013-06-05?20:33??ly\WebRoot\WEB-INF\classes\servlet\MainServlet.class
?????文件????????1270??2013-06-01?23:39??ly\WebRoot\WEB-INF\classes\servlet\RegisterServlet.class
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\WEB-INF\lib\
?????文件??????709922??2013-05-30?17:04??ly\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.7-bin.jar
?????文件??????231949??2013-05-27?11:23??ly\WebRoot\WEB-INF\lib\sqljdbc.jar
?????文件????????1131??2013-06-01?22:50??ly\WebRoot\WEB-INF\web.xm
?????目錄???????????0??2013-06-09?09:59??ly\WebRoot\img\
?????文件???????79109??2013-06-03?19:57??ly\WebRoot\img\1.jpg
?????文件??????104846??2013-06-03?19:57??ly\WebRoot\img\2.jpg
?????文件???????46657??2013-06-03?19:57??ly\WebRoot\img\3.jpg
?????文件???????35307??2013-06-03?19:57??ly\WebRoot\img\4.jpg
?????文件???????89597??2013-06-03?19:57??ly\WebRoot\img\5.jpg
?????文件?????????601??2013-06-03?20:21??ly\WebRoot\liuyan.jsp
............此處省略14個文件信息
- 上一篇:基于servlet和jsp的二手平臺交易系統
- 下一篇:db2驅動jar包
評論
共有 條評論