-
大小: 3.6MB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-09-20
- 語言: Java
- 標(biāo)簽:
資源簡介
該項(xiàng)目為在學(xué)習(xí)中做完的一個小型手機(jī)網(wǎng)站,用到了SQL server數(shù)據(jù)庫做前后臺的聯(lián)系,

代碼片段和文件信息
package?com.imti.dao;
import?java.sql.*;
/**
?*??SQL_SERVER數(shù)據(jù)庫連接實(shí)用工具類
?*?@author?IMTI?
?*?@version?1.0
?*?2008.09.01
?*?
?*/
public?class?DbUtil?{
private?Connection?conn=null;
private?PreparedStatement?pstmt=null;
private?ResultSet?rs=null;//結(jié)果集
public?DbUtil()
{
conn=getConnection();
}
public?static?DbUtil?Open()
{
return?new?DbUtil();
}
//創(chuàng)建數(shù)據(jù)庫連接
public?Connection?getConnection()
{
try{
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver“);//裝載驅(qū)動
String?url=“jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=nongye“;
conn=DriverManager.getConnection(url?“sa““123456“);
}catch(Exception?ex)
{
ex.printStackTrace();
System.out.println(“建立數(shù)據(jù)庫連接發(fā)生錯誤!“);
}
return?conn;
}
//數(shù)據(jù)庫查詢方法??select
public?ResultSet?query(String?sql)
{
try
{
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
}catch(Exception?e)
{
e.printStackTrace();
System.out.println(“查詢數(shù)據(jù)庫發(fā)生錯誤!“);
}
return?rs;
}
//insertupdatedelete
//insert?into?user(idnamepass)values(1‘a(chǎn)a‘‘bbb‘);
public?int?update(String?sql)
{
int?count=0;
try{
pstmt=conn.prepareStatement(sql);
count=pstmt.executeUpdate();
}catch(Exception?e)
{
e.printStackTrace();
System.out.println(“更新數(shù)據(jù)庫發(fā)生錯誤!“);
}
return?count;
}
//關(guān)閉數(shù)據(jù)庫連接
public?boolean?close()
{
boolean?isClose=false;
//關(guān)閉ResultSet
try{
if(rs!=null){
rs.close();
rs=null;
}
}catch(SQLException?ex)
{
rs=null;
isClose=false;
System.out.println(ex.getMessage());
System.out.println(“關(guān)閉結(jié)果集發(fā)生錯誤!“);
}
//關(guān)閉PreparedStatement
try{
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
}catch(SQLException?ex)
{
pstmt=null;
isClose=false;
System.out.println(ex.getMessage());
System.out.println(“關(guān)閉stmt發(fā)生錯誤!“);
}
//關(guān)閉Connection
try{
if(conn!=null){
conn.close();
conn=null;
}
}catch(SQLException?ex)
{
conn=null;
isClose=false;
System.out.println(ex.getMessage());
System.out.println(“關(guān)閉數(shù)據(jù)庫連接發(fā)生錯誤!“);
}
return?isClose;
}
public?static?void?main(String[]?args)?throws?SQLException{
DbUtil?util=DbUtil.Open();
ResultSet?rs?=?util.query(“select?*?from?users“);
while(rs.next())?{?
System.out.println(rs.getString(1)+“?“+rs.getString(2)+“?“+rs.getString(3));
}
util.close();
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????3550??2009-04-06?11:55??nongye\WebRoot\admin\mid.htm
?????文件???????1061??2009-04-11?22:38??nongye\WebRoot\admin\welcome.html
?????文件???????1335??2009-03-12?23:41??nongye\WebRoot\admin\images\back.bmp
?????文件???????1335??2009-03-12?23:41??nongye\WebRoot\image\back.bmp
?????文件????????524??2008-06-22?09:29??nongye\WebRoot\head\imaged\back.gif.bmp
?????文件????1270062??2009-04-04?20:30??nongye\WebRoot\admin\images\backg.bmp
?????文件???????2640??2009-03-26?11:52??nongye\WebRoot\image\btn_submit.bmp
?????文件???????5730??2009-04-06?15:52??nongye\WebRoot\admin\images\menu\chenggong.bmp
?????文件???????2070??2008-06-22?09:29??nongye\WebRoot\head\imaged\demo.bmp
?????文件???????2070??2008-06-22?09:29??nongye\WebRoot\image\demo.bmp
?????文件???????6450??2009-04-06?15:53??nongye\WebRoot\admin\images\menu\hangye.bmp
?????文件???????6102??2009-04-06?15:52??nongye\WebRoot\admin\images\menu\jingli.bmp
?????文件??????56022??2009-04-06?17:07??nongye\WebRoot\admin\images\jiuyi_top.bmp
?????文件??????37842??2008-06-22?09:29??nongye\WebRoot\head\imaged\logo.bmp
?????文件??????15544??2008-06-22?09:29??nongye\WebRoot\head\imaged\logo1.bmp
?????文件??????45738??2009-03-24?20:00??nongye\WebRoot\image\logo1.bmp
?????文件???????5794??2009-04-06?15:53??nongye\WebRoot\admin\images\menu\renli.bmp
?????文件???????6310??2009-04-06?15:53??nongye\WebRoot\admin\images\menu\shangwuli.bmp
?????文件???????5958??2009-04-06?15:52??nongye\WebRoot\admin\images\menu\shichang.bmp
?????文件???????4614??2008-06-22?09:29??nongye\WebRoot\head\imaged\submit.bmp
?????文件???????4614??2008-06-22?09:29??nongye\WebRoot\image\submit.bmp
?????文件????1327616??2009-06-03?16:59??nongye\db\nongye
?????文件???????3340??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\imti\dao\DbUtil.class
?????文件???????3730??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\imti\servlet\ImageServlet.class
?????文件???????2694??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\jspsmart\upload\ServletUpload.class
?????文件???????6173??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\jspsmart\upload\SmartFile.class
?????文件???????1817??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\jspsmart\upload\SmartFiles.class
?????文件???????1875??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\jspsmart\upload\SmartRequest.class
?????文件??????17520??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\jspsmart\upload\SmartUpload.class
?????文件????????386??2009-06-03?14:39??nongye\WebRoot\WEB-INF\classes\com\jspsmart\upload\SmartUploadException.class
............此處省略373個文件信息
評論
共有 條評論