package CrimeFile;
import com.sun.rowset.JdbcRowSetImpl;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.rowset.JdbcRowSet;
/**
*
* @author singgum3b
*/
public class test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// TODO code application logic here
JdbcRowSet jrsi=new JdbcRowSetImpl();
jrsi.setUrl("jdbc:sqlserver://localhost:1433;databaseName=CrimeFile");
jrsi.setUsername("sa");
jrsi.setPassword("hellokitty");
jrsi.setCommand("select * from dbo.Target");
jrsi.execute();
}
catch (SQLException ex) {
Logger.getLogger(test.class.getName()).log(Level.ALL, null, ex);
}
}
}
例外:Jdbcrowset错误?返回nullpointer异常!
Exception in thread "main" java.lang.NullPointerException
at com.sun.rowset.JdbcRowSetImpl.prepare(JdbcRowSetImpl.java:666)
at com.sun.rowset.JdbcRowSetImpl.execute(JdbcRowSetImpl.java:553)
at CrimeFile.test.main(test.java:30)
Java Result: 1
(第30行是crsi.excute();)
我使用的是SQL Server 2008和MS JDBC 3.0.I谷歌上搜索了一圈,发现了这段代码和Sun的例子一样link。我错了吗?
你试过另一个非常简单的表吗?因为虽然我没有MS SQL,但我用MySQL驱动程序尝试的代码基本相同,并没有任何问题。另外,你正在运行哪个JRE? – MJB 2011-05-01 18:53:08
我在一个只有1列的测试表上试过了,但是这看起来没有什么区别。我使用jre 6.此外,它似乎是jdbc驱动程序的问题,因为这里[链接](http://grepcode.com/ file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/rowset/JdbcRowSetImpl.java#JdbcRowSetImpl.execute%28%29) – Singgum3b 2011-05-01 19:00:29
是否可以尝试开源jtDS驱动程序? – MJB 2011-05-01 20:03:54