資源簡介
這是一個用jsp語言寫的一個用戶注冊和登錄系統,數據庫用的是MySQL,連接方式封裝到類里面。

代碼片段和文件信息
package?com;
import?java.sql.*;
import?java.lang.ClassNotFoundException;
public?class?baseConn?{
private?Connection?conn?=?null;
private?Statement?stmt?=?null;
private?PreparedStatement?ps?=?null;
private?ResultSet?rs?=?null;
public?baseConn()?throws?SQLExceptionClassNotFoundException{
try
{
String?url?=?“jdbc:mysql://localhost:3306/mytest“;
Class.forName(“com.mysql.jdbc.Driver“);
conn?=?DriverManager.getConnection(url“root““6121485“);
}catch(SQLException?e)
{
System.out.println(“Error?occured?when?Connect?Database:“+e);
throw?e;
}
catch(ClassNotFoundException?e)
{
System.out.println(“Error?occured?when?Connect?Database:“+e);
throw?e;
}
}
public?PreparedStatement?preparedStatement(String?sql)?throws?SQLException
{
try
{
ps?=?conn.prepareStatement(sql);
return?ps;
}catch(SQLException?e)
{
System.out.println(“Error?occured?when?Connect?Database:“+e);
throw?e;
}
}
/**
???*?執行靜態?SQL?查詢語句并返回它所生成結果的對象
???*?*/
??public?ResultSet?executeQuery(String?sql)?throws?SQLException
??{
????rs?=?null;
????try?{
??????rs?=?stmt.executeQuery(sql);
????}
????catch?(SQLException?ex)?{
??????System.out.println(“Error?occured?when?query?database:“?+?ex);
??????throw?ex;
????}
????return?rs;
??}
??
??/**
???*?執行靜態SQL更新語句并返回影響數據條數
???*?*/
??public?int?executeUpdate(String?sql)?throws?SQLException
??{
????try?{
??????conn.setAutoCommit(false);
??????int?re?=?stmt.executeUpdate(sql);
??????conn.commit();
??????return?re;
????}
????catch?(SQLException?e)?{
??????conn.rollback();
??????System.out.println(“Error?occured?when?update?database:“?+?e);
??????throw?e;
????}
??}??
??/**
???*?執行預編譯的SQL查詢語句
???*?
???*?*/
??public?ResultSet?executeQuery()?throws?SQLException
??{
????try?{
??????return?ps.executeQuery();
????}
????catch?(SQLException?e)?{
??????System.out.println(“Error?occured?when?query?database:“?+?e);
??????throw?e;
????}
??}
??/**
???*?執行預編譯的SQL更新語句
???*?
???*?*/
??public?int?executeUpdate()?throws?SQLException
??{
????try?{
??????conn.setAutoCommit(false);
??????int?r?=?ps.executeUpdate();
??????conn.commit();
??????return?r;
????}
????catch?(SQLException?e)?{
??????conn.rollback();
??????System.out.println(“Error?occured?when?update?database:“?+?e);
??????throw?e;
????}
??}
?/**
??*?數據庫關閉操作
??*?*/
??public?boolean?closeDB()?throws?SQLException
??{
????try?{
??????if?(this.rs?!=?null)
????????rs.close();
??????if?(this.stmt?!=?null)
????????this.stmt.close();
??????if?(this.ps?!=?null)
????????this.ps.close();
??????if?(this.conn?!=?null)
????????conn.close();
??????return?true;
????}
????catch?(SQLException?e)?{
??????System.out.println(“Error?occured?when?close?database:“?+?e);
??????throw?e;
????}
??}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????542??2009-07-13?09:05??testMySQL\.classpath
?????文件????????300??2009-07-11?11:26??testMySQL\.myme
?????文件???????1227??2009-07-11?12:37??testMySQL\.project
?????文件????????334??2009-07-11?11:26??testMySQL\.settings\org.eclipse.jdt.core.prefs
?????文件???????2990??2009-07-12?15:40??testMySQL\src\com\ba
?????文件???????2520??2009-07-13?10:27??testMySQL\src\com\CheckLogin.java
?????文件???????1848??2009-07-12?15:11??testMySQL\WebRoot\checkLogin.jsp
?????文件???????1967??2009-07-12?14:57??testMySQL\WebRoot\login.jsp
?????文件?????????39??2009-07-11?11:26??testMySQL\WebRoot\me
?????文件???????2026??2009-07-13?10:35??testMySQL\WebRoot\register.jsp
?????文件???????2162??2009-07-13?10:54??testMySQL\WebRoot\register_post.jsp
?????文件???????3162??2009-07-13?09:05??testMySQL\WebRoot\WEB-INF\classes\com\ba
?????文件???????2118??2009-07-13?10:27??testMySQL\WebRoot\WEB-INF\classes\com\CheckLogin.class
?????文件?????709922??2008-05-12?19:14??testMySQL\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.7-bin.jar
?????文件????????375??2009-07-12?14:35??testMySQL\WebRoot\WEB-INF\web.xm
?????文件????????844??2009-07-12?14:55??testMySQL\WebRoot\welcome.jsp
?????目錄??????????0??2009-07-13?10:58??testMySQL\WebRoot\WEB-INF\classes\com
?????目錄??????????0??2009-07-13?10:58??testMySQL\WebRoot\WEB-INF\classes
?????目錄??????????0??2009-07-13?10:58??testMySQL\WebRoot\WEB-INF\lib
?????目錄??????????0??2009-07-13?10:58??testMySQL\src\com
?????目錄??????????0??2009-07-13?10:58??testMySQL\WebRoot\me
?????目錄??????????0??2009-07-13?10:58??testMySQL\WebRoot\WEB-INF
?????目錄??????????0??2009-07-13?10:58??testMySQL\.myeclipse
?????目錄??????????0??2009-07-13?10:58??testMySQL\.settings
?????目錄??????????0??2009-07-13?10:58??testMySQL\src
?????目錄??????????0??2009-07-13?10:58??testMySQL\WebRoot
?????目錄??????????0??2009-07-13?10:58??testMySQL
-----------?---------??----------?-----??----
???????????????732376????????????????????27
............此處省略0個文件信息
- 上一篇:android購書系統
- 下一篇:操作系統實驗及其代碼Java編寫
評論
共有 條評論