版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔傾情為你奉上精選優(yōu)質(zhì)文檔傾情為你奉上專心專注專業(yè)專心專注專業(yè)精選優(yōu)質(zhì)文檔傾情為你奉上專心專注專業(yè) /連接數(shù)據(jù)庫方法類JDBCConnection.javapackage gj;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class JDBCConnection String driverName = com.mysql.jdbc.Driver; /驅(qū)動程序名 String userName = root; /數(shù)據(jù)庫用戶名 String use
2、rPwd = text; /密碼 String dbName = user; /數(shù)據(jù)庫名 String tableName = user_list3; /數(shù)據(jù)表名 String url =; public String getDriverName() return driverName;public void setDriverName(String driverName) this.driverName = driverName;public String getUserName() return userName;public void setUserName(String userNam
3、e) this.userName = userName;public String getUserPwd() return userPwd;public void setUserPwd(String userPwd) this.userPwd = userPwd;public String getDbName() return dbName;public void setDbName(String dbName) this.dbName = dbName;public String getTableName() return tableName;public void setTableName
4、(String tableName) this.tableName = tableName;public String getUrl() return url;public void setUrl(String url) this.url = url;/實現(xiàn)數(shù)據(jù)庫連接的方法 public Connection getConnection() throws SQLException, ClassNotFoundException /實現(xiàn)數(shù)據(jù)庫連接的方法 String url1=jdbc:mysql:/localhost:3306/+dbName; String url2 =?user=+user
5、Name+&password=+userPwd; String url3=&useUnicode=true&characterEncoding=GB2312; url =url1+url2+url3; Class.forName(driverName); return DriverManager.getConnection(url); /用戶登錄界面Index.jspMy JSP index.jsp starting page function validate() var userName=document.formsform1.UserName.value; var password=do
6、cument.formsform1.pd.value; if(userName.length=0) alert(用戶名不能為空!); else if(password=0) alert(密碼不能為空!); else document.formsform1.submit(); 用戶登錄 用戶名:密 碼: 注冊 /用戶登錄后臺驗證類CheckLogin.javapackage gj;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;p
7、ublic class CheckLogin private String name;private String password;public String getName() return name;public void setName(String name) = name;public String getPassword() return password;public void setPassword(String password) this.password = password;public CheckLogin(String name, String password)
8、 super(); = name;this.password = password;public int Check() throws SQLException, ClassNotFoundException JDBCConnection kkk = new JDBCConnection();Connection con = kkk.getConnection();Statement statement;try statement = con.createStatement();String sql = select * from user_list3 where name= + name +
9、 ;ResultSet rs = statement.executeQuery(sql);ResultSet rs1 = null;if (!rs.next() return 1; else String sql1 = select * from user_list3 where password=+ password + ;rs1 = statement.executeQuery(sql1);if (!rs1.next() return 2;rs.close();rs1.close();statement.close();con.close(); catch (Exception e) e.
10、printStackTrace();return 3;CheckLogin.java 中do post 方法request.setCharacterEncoding(GB2312);String name = request.getParameter(UserName);String pd = request.getParameter(pd);CheckLogin cl = new CheckLogin(name, pd);try switch (cl.Check() case 1:request.setAttribute(return,用戶名不存在!注冊?);request.getReque
11、stDispatcher(index.jsp).forward(request,response);break;case 2:request.setAttribute(return,密碼不存在!);request.getRequestDispatcher(index.jsp).forward(request,response);break;case 3:request.getRequestDispatcher(main.jsp).forward(request,response); catch (SQLException e1) / TODO Auto-generated catch bloc
12、ke1.printStackTrace(); catch (ClassNotFoundException e1) / TODO Auto-generated catch blocke1.printStackTrace();/用戶類package gj.user;public class user private String UserName; private String pd;public String getUserName() return UserName;public void setUserName(String userName) UserName = userName;pub
13、lic String getPd() return pd;public void setPd(String pd) this.pd = pd;public user(String userName, String pd) super();UserName = userName;this.pd = pd; /用戶注冊界面Register.JspMy JSP register.jsp starting page function fdate() var userName=.value; var password=document.formsform2
14、.password.value; var repassword=document.formsform2.repassword.value; if(userName.length=0) alert(用戶名不能為空!); else if(password=0) alert(密碼不能為空!); else if(password!=repassword) alert(兩次輸入密碼不一致!); else document.formsform2.submit(); 用戶注冊 用 戶 名:密 碼:再次輸入: 返回登錄界面/用戶注冊寫入數(shù)據(jù)庫servletRegister.jsppackage servlet
15、;import gj.JDBCConnection;import gj.getSQL;import java.io.IOException;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class register extends Http
16、Servlet public register() super();public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code herepublic void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doPost(request, response);public void doPost(HttpServletReques
17、t request, HttpServletResponse response)throws ServletException, IOException request.setCharacterEncoding(GB2312);String name = request.getParameter(name);String password = request.getParameter(password);JDBCConnection j = new JDBCConnection();try j.getConnection(); catch (SQLException e) / TODO Aut
18、o-generated catch blocke.printStackTrace(); catch (ClassNotFoundException e) / TODO Auto-generated catch blocke.printStackTrace();getSQL gl = new getSQL(name, password);try gl.getValue(); catch (ClassNotFoundException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (SQLException e) /
19、TODO Auto-generated catch blocke.printStackTrace();request.setAttribute(success, 注冊成功!);request.getRequestDispatcher(register.jsp).forward(request, response);/向數(shù)據(jù)庫中添加數(shù)據(jù)類package gj;import java.sql.Connection;import java.sql.SQLException;import java.sql.Statement;public class getSQL private String nam
20、e;private String password;public getSQL(String name, String password) super(); = name;this.password = password;public void getValue() throws ClassNotFoundException, SQLException JDBCConnection kkk=new JDBCConnection(); Connection con=kkk. getConnection() ; Statement statement = con.createStatement()
21、; String sql =insert into user_list3 values(+name+,+password+); statement. executeUpdate(sql); statement.close(); con.close(); /用戶查詢界面Query.jspMy JSP success.jsp starting page數(shù)據(jù)查詢按用戶查詢:查詢內(nèi)容如下:編號名字email%for (int i = 0; i 共有條記錄,查詢結(jié)果如上表所示!/學(xué)生類Student.javapublic class student private String number;priva
22、te String name;private String email;public String getNumber() return number;public void setNumber(String number) this.number = number;public String getName() return name;public void setName(String name) = name;public String getEmail() return email;public void setEmail(String email) this.email = emai
23、l;public student(String number, String name, String email) super();this.number = number; = name;this.email = email;public void getValue() throws ClassNotFoundException, SQLException JDBCConnection kkk=new JDBCConnection(); kkk.setTableName(student); Connection con=kkk. getConnection() ; Statement st
24、atement = con.createStatement(); String sql =insert into student values(+number+,+name+,+email+); statement. executeUpdate(sql); statement.close(); con.close(); /學(xué)生信息查詢類Query.javapackage gj.user;import gj.JDBCConnection;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLExceptio
25、n;import java.sql.Statement;public class query public query() public user Query(String sql) throws SQLException, ClassNotFoundException JDBCConnection kkk = new JDBCConnection();Connection con = kkk.getConnection();Statement statement = con.createStatement();ResultSet rs = statement.executeQuery(sql
26、);rs.last();user user2 = new userrs.getRow();rs.beforeFirst();int i = 0;while (rs.next() user2i = new user(rs.getString(name), rs.getString(password);i = i + 1;rs.close();statement.close();con.close();return user2;/學(xué)生信息查詢public student QueryStu(String sql) throws SQLException, ClassNotFoundException
27、JDBCConnection kkk = new JDBCConnection();kkk.setTableName(student);Connection con = kkk.getConnection();Statement statement = con.createStatement();ResultSet rs1 = statement.executeQuery(sql);rs1.last();student stu=new studentrs1.getRow();rs1.beforeFirst();int i=0;while(rs1.next()stui=new student(r
28、s1.getString(number),rs1.getString(name),rs1.getString(email);i+=1;rs1.close();statement.close();con.close();return stu;/數(shù)據(jù)添加類Insert.jspMy JSP insert.jsp starting page function validate2() var Number=document.formsform4.number.value; var Name=.value; var Email=document.formsf
29、orm4.email.value; if(Number.length=0) alert(學(xué)號不能為空!); else if(Name=0) alert(名字不能為空!); else if(Email=0) alert(email不能為空!) else document.formsform4.submit(); 學(xué)生信息添加學(xué)號姓名email /insert.java servlet do post()public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletExceptio
30、n, IOException request.setCharacterEncoding(GB2312);String number=request.getParameter(number);String name=request.getParameter(name);String email=request.getParameter(email);student st=new student(number,name,email);try st.getValue(); catch (ClassNotFoundException e) / TODO Auto-generated catch blo
31、cke.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();request.setAttribute(ok,添加成功!);request.getRequestDispatcher(insert.jsp).forward(request,response);/數(shù)據(jù)修改Update.jspMy JSP update.jsp starting page請選擇要修改的學(xué)生編號用戶名Email%for (int i = 0; i input type=radio na
32、me=check value=/顯示要修改的學(xué)生信息My JSP update1.jsp starting pagevar rdonly = false; function validate6() var Number=document.formsform5.number.value; var Name=.value; var Email=document.formsform5.email.value; if(Number.length=0) alert(學(xué)號不能為空!); else if(Name=0) alert(名字不能為空!); else
33、 if(Email=0) alert(email不能為空!) else document.formsform5.submit(); if(rdonly) document.getElementById(txtfield1).readOnly = false; rdonly = false; else document.getElementById(txtfield1).readOnly = true; rdonly = true; 學(xué)號:input type=text name=number id=txtfield1value=姓名:input type=text name=name valu
34、e=Email:input type=text name=email value=/update.java do post()public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException request.setCharacterEncoding(GB2312);String number=request.getParameter(number);String name=request.getParameter(name);Strin
35、g email=request.getParameter(email);Update up=new Update(number,name,email);try up.update(number); catch (ClassNotFoundException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();request.setAttribute(ok,修改成功!);request
36、.getRequestDispatcher(update.jsp).forward(request,response);/數(shù)據(jù)刪除Delete.jsp刪除學(xué)生請選擇要刪除的學(xué)生 編號 用戶名 Email % for(int i=0;i input type=checkbox name=check value= /刪除類Delete.jsp刪除學(xué)生請選擇要刪除的學(xué)生 編號 用戶名 Email % for(int i=0;i input type=checkbox name=check value= /學(xué)生修改類Update.jsppackage gj.user;import gj.JDBCConnection;import java.sql.Connection;import java.sql.SQLException;import java.sql.Statement;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江經(jīng)貿(mào)職業(yè)技術(shù)學(xué)院《與實踐》2023-2024學(xué)年第一學(xué)期期末試卷
- 中國民航大學(xué)《建筑概論B》2023-2024學(xué)年第一學(xué)期期末試卷
- 小學(xué)學(xué)校微信公眾號管理細(xì)則
- 浙江財經(jīng)大學(xué)《現(xiàn)代商務(wù)管理學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 缺陷管理與環(huán)境影響評估報告
- 新蘇教版一年級數(shù)學(xué)下冊第六單元《簡單的數(shù)量關(guān)系(一)》教案(共2課時)
- 大學(xué)生學(xué)生會主席離職工作總結(jié)報告演講稿王召鵬的
- 二零二五版建筑工程防水工程質(zhì)量檢測協(xié)議2篇
- 重慶市西南大學(xué)附屬中學(xué)2024-2025學(xué)年高一上學(xué)期定時檢測(二)物理試題(含答案)
- 2025屆湖南省衡陽縣第四中學(xué)高三上學(xué)期期末考試歷史試題(含答案)
- 園林景觀工程施工組織設(shè)計-投標(biāo)書范本
- 護(hù)理倫理學(xué)(第二版)高職PPT完整全套教學(xué)課件
- GB/T 25919.1-2010Modbus測試規(guī)范第1部分:Modbus串行鏈路一致性測試規(guī)范
- GB/T 22484-2008城市公共汽電車客運服務(wù)
- GB/T 14040-2007預(yù)應(yīng)力混凝土空心板
- 帶狀皰疹護(hù)理查房課件整理
- 奧氏體型不銹鋼-敏化處理
- 交通信號控制系統(tǒng)檢驗批質(zhì)量驗收記錄表
- 弱電施工驗收表模板
- 探究基坑PC工法組合鋼管樁關(guān)鍵施工技術(shù)
- 國名、語言、人民、首都英文-及各地區(qū)國家英文名
評論
0/150
提交評論