> Please someone explain why is "Object already closed" error occurred?
John

Add some logging to your code and figure out if you are closing your
database connection, but subsequently attempting to use a database resource
(like a result set).

A better place for these kinds of beginner questions is somewhere like
http://www.javaranch.com/.

Cheers
Kerry

On Sun, May 9, 2010 at 7:25 AM, Developer Coldfusion developer <
[email protected]> wrote:

> For such kind of code:
>
> 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();
> }
> }
> }
>
> I had following output:
>
> 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)
>
> Please someone explain why is "Object already closed" error occurred? John
>
> --
> 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.

Reply via email to