Jdbcrowset 错误?返回空指针异常!
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 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 的示例中的代码相同 链接 。我错了吗?
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
(line 30 is crsi.excute();)
I'm using sql server 2008 and ms jdbc 3.0.I googling around and found out this code is the same as in Sun's example link .Am i wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,并得出结论,问题是 Microsoft 驱动程序不支持
conn.prepareStatemen(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
的组合,如上所述在 Microsoft 网站
导致prepare()方法异常。
我从 这里创建了我自己的
MyJdbcRowSetImpl
并将prepareStatement
的参数更改为ResultSet.TYPE_SCROLL_SENSITIVE
Jtds 驱动程序不是解决方案,因为它不支持行集。
I was having the same problem and came to conclusion that the problem is that Microsoft driver doesnt support combination of
conn.prepareStatemen(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
as statedat microsoft website
resulting in exception of prepare() method.
I took source code from here created my own
MyJdbcRowSetImpl
and changed parameter ofprepareStatement
toResultSet.TYPE_SCROLL_SENSITIVE
Jtds driver wasnt solution as it doesnt support rowsets.
好吧,答案是切换到 JtDS 驱动程序,可以在 此处 找到该
驱动程序,MS JDBC 中显然有一些问题司机。
Ok, the answer was to switch to JtDS driver, which can be found here
There's clearly something bollixed up in MS JDBC driver.
我记得这个 NullPointerException 发生在我身上,但只有当我不应该这样做时调用execute(),即使用带有 ResultSet 作为参数的 JdbcRowSetImpl 时
I remember this NullPointerException happening to me but only if I call execute() when I should NOT be doing so i.e. when using JdbcRowSetImpl with a ResultSet as argument