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

发布于 2024-11-05 01:41:21 字数 1501 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脸赞 2024-11-12 01:41:21

我遇到了同样的问题,并得出结论,问题是 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 stated
at microsoft website
resulting in exception of prepare() method.
I took source code from here created my own MyJdbcRowSetImpl and changed parameter of prepareStatement to ResultSet.TYPE_SCROLL_SENSITIVE

Jtds driver wasnt solution as it doesnt support rowsets.

森末i 2024-11-12 01:41:21

好吧,答案是切换到 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.

飘落散花 2024-11-12 01:41:21

我记得这个 NullPointerException 发生在我身上,但只有当我不应该这样做时调用execute(),即使用带有 ResultSet 作为参数的 JdbcRowSetImpl 时

private JdbcRowSet executeWithResultSet(Connection conn, String sqlQuery)
        throws SQLException {
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sqlQuery);
    JdbcRowSet jdbcRs = new JdbcRowSetImpl(rs);
    jdbcRs.execute(); //<-- results to the error as reported

    return jdbcRs;
}

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

private JdbcRowSet executeWithResultSet(Connection conn, String sqlQuery)
        throws SQLException {
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sqlQuery);
    JdbcRowSet jdbcRs = new JdbcRowSetImpl(rs);
    jdbcRs.execute(); //<-- results to the error as reported

    return jdbcRs;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文