gpt4 book ai didi

java - Jdbcrowset 错误?返回空指针异常!

转载 作者:行者123 更新时间:2023-11-29 06:13:48 24 4
gpt4 key购买 nike

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);
}
}
}

异常(exception):

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。我四处搜索,发现这段代码与 Sun 的示例中的代码相同 link .我错了吗?

最佳答案

我遇到了同样的问题并得出结论,问题是 Microsoft 驱动程序不支持 conn.prepareStatemen(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); 的组合,如所述 at microsoft website导致 prepare() 方法异常。我从 here 中获取了源代码创建了我自己的 MyJdbcRowSetImpl 并将 prepareStatement 的参数更改为 ResultSet.TYPE_SCROLL_SENSITIVE

Jtds 驱动程序不是解决方案,因为它不支持行集。

关于java - Jdbcrowset 错误?返回空指针异常!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5848757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com