System.out.println(rs2==null); returned true into stream. So, how to do that correctly? It throws an exception for using execute(). John
2010/5/5 Kerry Sainsbury <[email protected]> > I'm guessing line 25 is "while(rs2.next())", therefore "rs2" must be null. > > Do other databases return non-null result sets after INSERTs? > > > On Thu, May 6, 2010 at 6:08 AM, Developer Coldfusion developer < > [email protected]> wrote: > >> I tried to do this: >> >> >> import java.sql.Connection; >> import java.sql.DriverManager; >> import java.sql.ResultSet; >> import java.sql.SQLException; >> import org.h2.util.Profiler; >> public class Profile { >> private static Profiler prof; >> /** >> * @param args >> * @throws ClassNotFoundException >> * @throws SQLException >> */ >> public static void main(String[] args) throws >> ClassNotFoundException, >> SQLException { >> Class.forName("org.h2.Driver"); >> Connection conn = >> DriverManager.getConnection("jdbc:h2:tcp:// >> localhost/~/test", "sa", ""); >> java.sql.Statement stat = conn.createStatement(); >> prof = new Profiler(); >> ResultSet rs = stat.executeQuery("SELECT 'Hello World'"); >> while (rs.next()) >> { >> System.out.println(rs.getString(1)); >> } >> stat.executeUpdate("insert into test_table (id,resolver) >> values ( 3, >> 'Quest') "); >> ResultSet rs2 = stat.getResultSet(); >> while(rs2.next()) >> { >> System.out.println(rs.getInt("id")); >> System.out.println(rs.getString("resolver")); >> } >> prof.stopCollecting(); >> System.out.println(prof.getTop(3)); >> conn.close(); >> } >> >> } >> >> and got an error: >> >> Hello World >> Exception in thread "main" java.lang.NullPointerException >> at Profile.main(Profile.java:25) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "H2 Database" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<h2-database%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/h2-database?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "H2 Database" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<h2-database%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/h2-database?hl=en. > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
