设备管理系统源代码.doc

上传人:wj 文档编号:232629 上传时间:2023-04-28 格式:DOC 页数:6 大小:22KB
下载 相关 举报
设备管理系统源代码.doc_第1页
第1页 / 共6页
设备管理系统源代码.doc_第2页
第2页 / 共6页
设备管理系统源代码.doc_第3页
第3页 / 共6页
设备管理系统源代码.doc_第4页
第4页 / 共6页
设备管理系统源代码.doc_第5页
第5页 / 共6页
设备管理系统源代码.doc_第6页
第6页 / 共6页
亲,该文档总共6页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

设备管理系统源代码.doc

《设备管理系统源代码.doc》由会员分享,可在线阅读,更多相关《设备管理系统源代码.doc(6页珍藏版)》请在冰点文库上搜索。

设备管理系统源代码.doc

packagecom.DB;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

publicclassDBManager{

privatefinalstaticStringdriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";

privatefinalstaticStringurl="jdbc:

microsoft:

sqlserver:

//127.0.0.1:

1433;DataBaseName=bbsDB";

privateConnectionconn;

privateStatementst;

privateResultSetrs;

/**

*创建连接

*@return

*/

publicConnectiongetConnection(){

if(conn==null){

try{

Class.forName(driver);

conn=DriverManager.getConnection(url,"sa","root");

}catch(ClassNotFoundExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

returnconn;

}

/**

*创建statement

*/

publicStatementgetStatement(){

if(st==null){

try{

st=conn.createStatement();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

returnst;

}

/**

*执行更新操作

*/

publicintupdate(Stringsql){

System.out.println(">>>>>>>>===="+sql);

getConnection();

introws=0;

st=getStatement();

try{

rows=st.executeUpdate(sql);

}catch(SQLExceptione){

e.printStackTrace();

}finally{

closeAll();

}

returnrows;

}

/**

*使用预处理

*/

publicintupdate(Stringsql,Stringdata[]){

System.out.println(">>>>==="+sql);

getConnection();

try{

intindex=0;

PreparedStatementpst=conn.prepareStatement(sql);

for(inti=0;i

pst.setString(++index,data[i]);

}

returnpst.executeUpdate();

}catch(SQLExceptione){

e.printStackTrace();

}finally{

closeAll();

}

return0;

}

/**

*执行查询操作

*/

publicResultSetgetQuery(Stringsql){

System.out.println(">>>>>>>>===="+sql);

getConnection();

st=getStatement();

try{

rs=st.executeQuery(sql);

}catch(SQLExceptione){

e.printStackTrace();

}

returnrs;

}

/**

*执行关闭

*/

publicvoidcloseAll(){

if(rs!

=null){

try{

rs.close();

rs=null;

}catch(SQLExceptione){

e.printStackTrace();

}

}

if(st!

=null){

try{

st.close();

st=null;

}catch(SQLExceptione){

e.printStackTrace();

}

}

if(conn!

=null){

try{

conn.close();

conn=null;

}catch(SQLExceptione){

e.printStackTrace();

}

}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2