try{
Connection conn=mytools.getConn();
//Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement st=conn.createStatement();
String sql="select * from Strainlib_Chip where Strain_ID like 'hs001a%' order by Strain_ID ASC";
ResultSet rs=st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
if (rs.isLast())
System.out.println("OK");
else
System.out.println("false");
}catch (SQLException ex){
System.out.println("error");
}
---------------------------------------
系统始终抛出SQLException异常,我该怎么做?
Connection conn=mytools.getConn();
//Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement st=conn.createStatement();
String sql="select * from Strainlib_Chip where Strain_ID like 'hs001a%' order by Strain_ID ASC";
ResultSet rs=st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
if (rs.isLast())
System.out.println("OK");
else
System.out.println("false");
}catch (SQLException ex){
System.out.println("error");
}
---------------------------------------
系统始终抛出SQLException异常,我该怎么做?
因为里面的很多调用都要SQLException产生的
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
This JDBC 2.0 method is not implemented
at weblogic.jdbc.mssqlserver4.TdsConnection.createStatement(TdsConnectio
n.java:539)
at example.main(example.java:19)
....
} catch (SQLException ex){
System.out.println("error");
System.out.println(ex.getMessage());//看看是什么东东
ex.printStackTrace();//看看到底是那一句出了异常
}ResultSet总是跟产生它的Statement有关联,只有当Statement关闭close或重新执行或检索后面的ResultSet时,当前ResultSet才自动关闭。你的程序里没有上面列举的行为!其实,现在很多数据库JBDC Driver都很健壮,当语句Statement执行insert或update等非查询行为时,当前ResulstSet也常常不自动关闭。所以,我的经验是,一个Statement在同一时刻只能维持一个ResultSet!
看来你的Driver比较落伍,只支持用一般的语句
Statement st=conn.createStatement();
它肯定支持了,要不然.....faint
我用了,系统除了能执行rs.next()外,First(), Last()等等都报异常!
是不是我的开发环境有问题?
weblogic7.0, SQLServer2000, JDK1.3
可以实现Clonable2.SQLException:
该驱动没有实现这些方法,所以不能用,试试看其他的
给个example.
若你的JDBC驱动程序不支持“敏感滚动”;
我用了,系统除了能执行rs.next()外,First(), Last()等等都报异常!
是不是我的开发环境有问题?
weblogic7.0, SQLServer2000, JDK1.3
绝对是JDBC驱动程序不支持,取消"敏感滚动",只用next()即可,不然重新下载
JDBC 2.0以上的驱动程序
1,更换高级的driver,使用JDBC2.0以上api
2,降低需求,避免使用JDBC2.0以上api
3,到java.sun.com去当rowset.jar,这样可以把结果集缓存到CachedRowSet里,部分的解决问题
//the following code, hope it will give a basic idea
//the code below will use JDBC to connect to your data source
//read ALL the data inside and print out in you console window
//IF YOU CAN GET THIS JOB DONE I THINK YOU WILL ABTAIN A LOT!!
//step1
//use microsoft Access to create a table named BOOKS.//step2
//establish a data source naemed "BooksInfoODBC"(quote not include)
//if you don't how to create a data source in you computer,
//check with your frieds//step 3
//create a java class and run the following codeimport java.io.*;
import java.sql.*;public class Test1 {
public static void main(String[] args) {
try {
// loads the jdbc odbc bridge driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e) {
System.err.println("Error" + e) ;
}
try {
// establish db connection through a Connection object
Connection con = DriverManager.getConnection("jdbc:odbc:BooksInfoODBC") ; // instance of a sql statement
Statement stmt = con.createStatement(); // prepare sql statement
String sqlStr = "SELECT * FROM BOOKS"; // execute the SELECT query through executeQuery()
// save the result in ResultSet
ResultSet rs = stmt.executeQuery(sqlStr); // process the result of the ResultSet
System.out.println(" the records selected are");
ResultSetMetaData info = rs.getMetaData(); while (rs.next()) {
for (int i=1; i<=info.getColumnCount(); i++) {
System.out.print("\t" + rs.getString(i));
}
System.out.println();
} // close the ResultSet, Statement and Connection objects
rs.close();//************************************************
stmt.close();//**********************************************
con.close();//***********************************************
}
catch (SQLException e) {
System.err.println("Error " + e);
}
}
}//disable the codes with star. i mean, do not
//close your resultset,your statement,you connetion
//before you really want to quit, then you can use the
//resultset as many times as possible before you run
//the code with star sign