代码如下:
import java.sql.*;
import com.sun.rowset.CachedRowSetImpl;
import javax.sql.rowset.*;
public class test {
public test()
{
testcode();
}
public void testcode()
{
String sql;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String url="jdbc:odbc:workflow";
String user="";
String password="";
conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
CachedRowSetImpl rowset = new CachedRowSetImpl();
ResultSet rs = stmt.executeQuery("select * from workerinfo"); rowset.populate(rs);
while(rowset.next())
{ System.out.println("name:"+rowset.getString(1));
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new test();
}
private Statement stmt;
private Connection conn;
}程序能运行 但是rowset.getString(1)返回的结果都是null,如果换成rs.getString(1)则能成功得到结果
import java.sql.*;
import com.sun.rowset.CachedRowSetImpl;
import javax.sql.rowset.*;
public class test {
public test()
{
testcode();
}
public void testcode()
{
String sql;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String url="jdbc:odbc:workflow";
String user="";
String password="";
conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
CachedRowSetImpl rowset = new CachedRowSetImpl();
ResultSet rs = stmt.executeQuery("select * from workerinfo"); rowset.populate(rs);
while(rowset.next())
{ System.out.println("name:"+rowset.getString(1));
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new test();
}
private Statement stmt;
private Connection conn;
}程序能运行 但是rowset.getString(1)返回的结果都是null,如果换成rs.getString(1)则能成功得到结果
import com.sun.rowset.CachedRowSetImpl;
import javax.sql.rowset.*;public class Test
{
public Test(){
}
public void testcode(){
String sql;
try{
String url="jdbc:h2:workerinfo";
String user="sa";
String password="";
Connection conn = DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
stmt.executeUpdate("drop table if exists workerinfo");
stmt.executeUpdate("create table if not exists workerinfo (name VARCHAR(20))");
stmt.executeUpdate("insert into workerinfo (name) values ('jack')"); CachedRowSetImpl rowset = new CachedRowSetImpl();
ResultSet rs = stmt.executeQuery("select * from workerinfo"); rowset.populate(rs);
while(rowset.next()) {
System.out.println("name:"+rowset.getString(1));
}
rowset.close();
rs.close();
stmt.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
}
} public static void main(String[] args){
new Test().testcode();
}
}java -cp .:h2.jar Test
name:jack