程序如下:
//eee.java
import java.sql.*;
import java.io.*;public class eee extends Thread
{
static int la=0; //计数器
public static void main(String[] args)
{// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost;instanceName=Sa;" +
"user=Sa;password=Sa"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rs1 = null;
int count=0;
String SQL=null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
stmt = con.createStatement();
count = stmt.executeUpdate("use db_qh"); SQL="select * from [20070104SQru01] where Time>'2007-01-04 08:30' and Time<='2007-01-04 09:05' order by Time";
rs = stmt.executeQuery(SQL); SQL="select A.*,B.* from SQcu5k A,SQru5k B where A.time=B.time order by A.time";
rs1 = stmt.executeQuery(SQL);for(int i=0;i<5;i++)
{
rs.next();
System.out.println(rs.getDouble(1));
rs1.next();
System.out.println(rs1.getDouble(1));}
} // Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}我执行这个程序,返回给我的异常是结果集已关闭.
请高手指点一二,谢谢哈
//eee.java
import java.sql.*;
import java.io.*;public class eee extends Thread
{
static int la=0; //计数器
public static void main(String[] args)
{// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost;instanceName=Sa;" +
"user=Sa;password=Sa"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rs1 = null;
int count=0;
String SQL=null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
stmt = con.createStatement();
count = stmt.executeUpdate("use db_qh"); SQL="select * from [20070104SQru01] where Time>'2007-01-04 08:30' and Time<='2007-01-04 09:05' order by Time";
rs = stmt.executeQuery(SQL); SQL="select A.*,B.* from SQcu5k A,SQru5k B where A.time=B.time order by A.time";
rs1 = stmt.executeQuery(SQL);for(int i=0;i<5;i++)
{
rs.next();
System.out.println(rs.getDouble(1));
rs1.next();
System.out.println(rs1.getDouble(1));}
} // Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}我执行这个程序,返回给我的异常是结果集已关闭.
请高手指点一二,谢谢哈
count = stmt.executeUpdate("use db_qh"); SQL="select * from [20070104SQru01] where Time>'2007-01-04 08:30' and Time <='2007-01-04 09:05' order by Time";
rs = stmt.executeQuery(SQL); SQL="select A.*,B.* from SQcu5k A,SQru5k B where A.time=B.time order by A.time";
stmt = con.createStatement();//需要重新得到
rs1 = stmt.executeQuery(SQL);
搞一次时,就stmt.close();第二次在开
你说的我按以下的代码试了试
没有用哈 stmt = con.createStatement();
count = stmt.executeUpdate("use db_qh"); SQL="select * from [20070104SQru01] where Time>'2007-01-04 08:30' and Time<='2007-01-04 09:05' order by Time";
rs = stmt.executeQuery(SQL);
stmt.close(); stmt = con.createStatement();
SQL="select A.*,B.* from SQcu5k A,SQru5k B where A.time=B.time order by A.time";
rs1 = stmt.executeQuery(SQL);
stmt1 = con.createStatement();
count = stmt.executeUpdate("use db_qh");
count = stmt1.executeUpdate("use db_qh"); SQL="select * from [20070104SQru01] order by Time";
rs = stmt.executeQuery(SQL); SQL="select A.*,B.* from SQcu5k A,SQru5k B where A.time=B.time order by A.time";
rs1 = stmt1.executeQuery(SQL);用了这个代码,成功了.感谢两位的提醒,马上结帖