当前位置: 技术问答>java相关
我的数据库连接函数,为什么不能不同对两个表的查询操作.
来源: 互联网 发布时间:2015-07-21
本文导语: 如: Rs=OpenDb.execuQuery("SELECT * FROM user"); Rs1=OpenDb.execuQeury("SELECT * FROM menu"); if(Rs.next()){ ....... } 系统提示Rs已关闭. import java.sql.*; public class OpenDb { Connection ConDB=null; Statement Stmt=null; ResultSet Rs=null; public ...
如:
Rs=OpenDb.execuQuery("SELECT * FROM user");
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
if(Rs.next()){
.......
}
系统提示Rs已关闭.
import java.sql.*;
public class OpenDb
{
Connection ConDB=null;
Statement Stmt=null;
ResultSet Rs=null;
public OpenDb(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
ConDB=DriverManager.getConnection("jdbc:odbc:easy");
Stmt=ConDB.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex){
System.err.println(ex.getMessage());
}
}
public void Close(){
try{
Rs.close();
Stmt.close();
ConDB.close();
}
catch(Exception ex){
System.err.println(ex.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
Rs=Stmt.executeQuery(sql);
}
catch(Exception ex){
System.err.println("sq.executeQuery:"+ex.getMessage());
}
return Rs;
}
public int executeUpdate(String sql){
int rc=0;
try{
rc=Stmt.executeUpdate(sql);
}
catch(Exception ex){
System.err.println("sq.executeUpdate:"+ex.getMessage());
return -1;
}
return rc;
}
}
Rs=OpenDb.execuQuery("SELECT * FROM user");
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
if(Rs.next()){
.......
}
系统提示Rs已关闭.
import java.sql.*;
public class OpenDb
{
Connection ConDB=null;
Statement Stmt=null;
ResultSet Rs=null;
public OpenDb(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
ConDB=DriverManager.getConnection("jdbc:odbc:easy");
Stmt=ConDB.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex){
System.err.println(ex.getMessage());
}
}
public void Close(){
try{
Rs.close();
Stmt.close();
ConDB.close();
}
catch(Exception ex){
System.err.println(ex.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
Rs=Stmt.executeQuery(sql);
}
catch(Exception ex){
System.err.println("sq.executeQuery:"+ex.getMessage());
}
return Rs;
}
public int executeUpdate(String sql){
int rc=0;
try{
rc=Stmt.executeUpdate(sql);
}
catch(Exception ex){
System.err.println("sq.executeUpdate:"+ex.getMessage());
return -1;
}
return rc;
}
}
|
可以的阿,我跟你的差不多,而且经常这样做
你这样试试,肯定没问题的
Rs=OpenDb.execuQuery("SELECT * FROM user");
if(Rs.next()){
.......
}
openDb.close();
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
你这样试试,肯定没问题的
Rs=OpenDb.execuQuery("SELECT * FROM user");
if(Rs.next()){
.......
}
openDb.close();
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
|
你试试这样,肯定没问题的
Rs=OpenDb.execuQuery("SELECT * FROM user");
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
if(Rs.next()){
.......
}
OpenDb.close();
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
Rs=OpenDb.execuQuery("SELECT * FROM user");
Rs1=OpenDb.execuQeury("SELECT * FROM menu");
if(Rs.next()){
.......
}
OpenDb.close();
Rs1=OpenDb.execuQeury("SELECT * FROM menu");