Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Database/JDBC/SQL/JDO/Hibernate
» MS SQL
打印话题 寄给朋友 订阅主题 |
作者 | JDBC Object has been closed |
huajiazhou
发贴: 14 积分: 0 |
于 2005-05-21 23:55
JAVABEAN连接数据库的代码! import java.sql.*; import java.lang.*; public class sqlBean{ public Connection conn=null; public ResultSet rs=null; private String DatabaseDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; private String DbConnStr="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mis"; private String User="sa"; private String Pswd="5696285"; public void setDatabaseDriver(String dbDriver){ this.DatabaseDriver=dbDriver; } public void setDatabaseConnStr(String ConnStr){ this.DbConnStr=ConnStr; } public void setUser(String user){ this.User=user; } public void setPassword(String pwd){ this.Pswd=pwd; } public String getDatabaseDriver(){ return (this.DatabaseDriver); } public String getDatabaseConnStr(){ return (this.DbConnStr); } // constructor public sqlBean(){ try{ Class.forName(DatabaseDriver);//.newInstance(); }catch(ClassNotFoundException e){ System.out.println("Load DB Driver Error:"+e.getMessage()); } try{ conn = DriverManager.getConnection(DbConnStr,User,Pswd); }catch(Exception ex){ System.out.println("Query Error:"+ex.getMessage()); } } public int executeInsert(String sql){ int num=0; try{ Statement stmt=conn.createStatement(); num=stmt.executeUpdate(sql); }catch(SQLException ex){ System.out.println("Insert Data Error:"+ex.getMessage()); } CloseDataBase(); return num; } public ResultSet executeQuery(String sql){ rs=null; try{ Statement stmt=conn.createStatement(); rs=stmt.executeQuery(sql); }catch(SQLException ex){ System.out.println("Query Error:"+ex.getMessage()); } CloseDataBase(); return rs; } public int executeDelete(String sql){ int num=0; try{ //conn = DriverManager.getConnection(DbConnStr,User,Pswd); Statement stmt=conn.createStatement(); num=stmt.executeUpdate(sql); }catch(SQLException ex){ System.out.println("Delete Data Error:"+ex.getMessage()); } CloseDataBase(); return num; } // Close the DB public void CloseDataBase(){ try{ conn.close(); }catch(Exception end){ System.out.println("Can not close the DB:"+end.getMessage()); } } } 编译没错,但是实际运用在JSP里面后提示java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Object has been closed. 的错误! 请大家指教啊!这个问题搞的我想自杀,一直解决不了! Java应用者与<IDE/环境> |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
16078 | JDBC Object has been closed | huajiazhou | 2375 | 2005-05-21 23:55 |
13207 | Re:JDBC Object has been closed | huajiazhou | 29 | 2005-05-21 23:55 |
12990 | Re:JDBC Object has been closed | why | 117 | 2005-05-22 03:06 |
14147 | Re:JDBC Object has been closed | huajiazhou | 109 | 2005-05-22 13:57 |
13887 | Re:JDBC Object has been closed | yhjvcnet | 56 | 2005-06-02 14:31 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |