Reputation: 86
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?
Upvotes: 1
Views: 1530
Reputation: 503
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.
Upvotes: 2
Reputation: 1
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;
}
Upvotes: 0