I understood that. So I made a new workaround and coded this:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.util.Profiler;
import java.util.List;
import java.util.logging.Logger;
public class Profile {
private static Profiler prof;
private static Logger log4j_logger;
/**
* @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();
new java.util.logging.LoggingMXBean()
{
@Override
public String getLoggerLevel(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> getLoggerNames() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getParentLoggerName(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setLoggerLevel(String arg0, String arg1) {
// TODO Auto-generated method stub
}
};
log4j_logger = java.util.logging.Logger.getLogger("sdk");
prof.startCollecting();
ResultSet rs = stat.executeQuery("SELECT 'Hello World'");
prof.stopCollecting();
while (rs.next())
{
System.out.println(rs.getString(1));
stat.executeUpdate("insert into test_table (id,resolver) values ( 2,
'Retail') ");
Statement profiled_statement = conn.createStatement();
ResultSet rs_debug = profiled_statement.executeQuery("select * from
test_table");
while(rs_debug.next())
{
System.out.println(1);
//log4j_logger.log(log4j_logger.getLevel(),
String.valueOf(rs_debug.getInt("id")));
//log4j_logger.log(log4j_logger.getLevel(),
String.valueOf(rs_debug.getString("resolver")));
}
//prof.stopCollecting();
System.out.println(prof.getTop(-3));
conn.close();
}
}
}
and got following:
Hello World
1
1
1
1
1
Profiler: top -3 stack trace(s) of 52 ms [build-132]
1/1
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:199)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at
sun.security.provider.SeedGenerator$URLSeedGenerator.getSeedByte(SeedGenerator.java:453)
at sun.security.provider.SeedGenerator.getSeedBytes(SeedGenerator.java:123)
at sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.java:118)
at
sun.security.provider.SecureRandom.engineGenerateSeed(SecureRandom.java:114)
at java.security.SecureRandom.generateSeed(SecureRandom.java:495)
at org.h2.util.MathUtils$1.run(MathUtils.java:62)
at java.lang.Thread.run(Thread.java:619)
.
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Объект уже закрыт
The object is already closed [90007-132]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.message.DbException.get(DbException.java:133)
at org.h2.jdbc.JdbcResultSet.checkClosed(JdbcResultSet.java:2923)
at org.h2.jdbc.JdbcResultSet.next(JdbcResultSet.java:115)
at Profile.main(Profile.java:54)
I have three questions:
1. Why is an argument in docs for a Profiler.getTop(...) is positive number,
but none positive argument gives results. But negative ones give. Why is
that so?
2. Why I have got JDBCException "Object already closed"?
John
2010/5/6 Christian Peter <[email protected]>
> Hi,
>
> executeUpdate does not produce a result set. Therefore the result is
> null (you can't get the content of the table if you do an insert):
>
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#getResultSet%28%29
>
> To get a result set you'd have to execute a query:
>
> ResultSet rs2 = stat.executeQuery("select id,resolver from
> test_table");
>
> Regards
>
> Christian
>
>
> On May 6, 3:46 pm, Developer Coldfusion developer
> <[email protected]> wrote:
> > 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]>
> <h2-database%[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]>
> <h2-database%[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 athttp://
> 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.