From: Ezequiel C. <eco...@gm...> - 2010-01-21 19:02:35
|
Hi, I have a problem when I try to connect with the database H2 through TCP. I'm doing this: Map<String,String> params = new HashMap<String,String>(); //If I use this way, the database is embedded, this has no problem //params.put(H2DataStoreFactory.DATABASE.key, "/home/mmassigoge/test"); //When I try this url the result is invalid format //params.put(H2DataStoreFactory.DATABASE.key, "jdbc:h2:tcp://localhost:9092/~/test"); //with thi URL the result is invalid file or header // params.put(H2DataStoreFactory.DATABASE.key, "jdbc:h2:tcp//localhost:9092/~/test"); params.put(H2DataStoreFactory.DBTYPE.key, "h2"); params.put(H2DataStoreFactory.PORT.key, "9092"); params.put(H2DataStoreFactory.HOST.key, "localhost"); try { this.datastore = DataStoreFinder.getDataStore(params); } catch (IOException e) { e.printStackTrace(); } I have this exception: Exception in thread "main" java.lang.RuntimeException: Unable to obtain connection at org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:1385) at org.geotools.jdbc.JDBCDataStore.createTypeNames(JDBCDataStore.java:696) at org.geotools.data.store.ContentDataStore.getTypeNames(ContentDataStore.java:270) at org.geotools.data.store.ContentDataStore.getNames(ContentDataStore.java:631) at PruebaConexion.inspeccionar(PruebaConexion.java:76) at PruebaConexion.main(PruebaConexion.java:46) Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Versión del archivo de base de datos no soportada ó encabezado de archivo invalido en archivo jdbc:h2:tcp//localhost:9092/~/test.data.db Unsupported database file version or invalid file header in file jdbc:h2:tcp//localhost:9092/~/test.data.db [90048-104]) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:1377) ... 5 more Caused by: org.h2.jdbc.JdbcSQLException: Versión del archivo de base de datos no soportada ó encabezado de archivo invalido en archivo jdbc:h2:tcp//localhost:9092/~/test.data.db Unsupported database file version or invalid file header in file jdbc:h2:tcp//localhost:9092/~/test.data.db [90048-104] at org.h2.message.Message.getSQLException(Message.java:103) at org.h2.message.Message.getSQLException(Message.java:114) at org.h2.message.Message.getSQLException(Message.java:77) at org.h2.engine.Database.isTextStorage(Database.java:278) at org.h2.engine.Database.open(Database.java:537) at org.h2.engine.Database.<init>(Database.java:211) at org.h2.engine.Engine.openSession(Engine.java:57) at org.h2.engine.Engine.openSession(Engine.java:126) at org.h2.engine.Engine.getSession(Engine.java:109) at org.h2.engine.Session.createSession(Session.java:309) at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:251) at org.h2.engine.SessionRemote.createSession(SessionRemote.java:229) at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111) at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95) at org.h2.Driver.connect(Driver.java:54) at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221) ... 7 more This database was created with the same JAR that GeoServer through the console. With JDBC through TCP I can connect without problem Class.forName("org.h2.Driver"); Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9092/~/test", "", ""); conn.createStatement().executeUpdate("CREATE TABLE BORRAR(id int);"); conn.close(); Thanks! Ezequiel. |
From: andrea a. <and...@gm...> - 2010-01-22 08:22:13
|
Hi Ezequiel, On Thu, Jan 21, 2010 at 8:02 PM, Ezequiel Coronel <eco...@gm...> wrote: > Hi, I have a problem when I try to connect with the database H2 through > TCP. > > I'm doing this: > Map<String,String> params = new HashMap<String,String>(); > > //If I use this way, the database is embedded, this has no problem > //params.put(H2DataStoreFactory.DATABASE.key, > "/home/mmassigoge/test"); > > //When I try this url the result is invalid format > //params.put(H2DataStoreFactory.DATABASE.key, > "jdbc:h2:tcp://localhost:9092/~/test"); > > //with thi URL the result is invalid file or header > // params.put(H2DataStoreFactory.DATABASE.key, > "jdbc:h2:tcp//localhost:9092/~/test"); > > params.put(H2DataStoreFactory.DBTYPE.key, "h2"); > > params.put(H2DataStoreFactory.PORT.key, "9092"); > params.put(H2DataStoreFactory.HOST.key, "localhost"); The following for me works: params.put(JDBCDataStoreFactory.DBTYPE.key, "h2"); params.put(JDBCDataStoreFactory.DATABASE.key, database); params.put(JDBCDataStoreFactory.PORT.key, port); params.put(JDBCDataStoreFactory.HOST.key, host); params.put(JDBCDataStoreFactory.USER.key, user); params.put(JDBCDataStoreFactory.PASSWD.key, passwd); Where to fill in the vars, the url as you use it would be: String url = "jdbc:h2:tcp://" + host + ":" + port + "/" + database; Ciao Andrea > try { > this.datastore = DataStoreFinder.getDataStore(params); > } catch (IOException e) { > e.printStackTrace(); > } > > I have this exception: > Exception in thread "main" java.lang.RuntimeException: Unable to obtain > connection > at > org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:1385) > at org.geotools.jdbc.JDBCDataStore.createTypeNames(JDBCDataStore.java:696) > at > org.geotools.data.store.ContentDataStore.getTypeNames(ContentDataStore.java:270) > at > org.geotools.data.store.ContentDataStore.getNames(ContentDataStore.java:631) > at PruebaConexion.inspeccionar(PruebaConexion.java:76) > at PruebaConexion.main(PruebaConexion.java:46) > Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create > PoolableConnectionFactory (Versión del archivo de base de datos no soportada > ó encabezado de archivo invalido en archivo > jdbc:h2:tcp//localhost:9092/~/test.data.db > Unsupported database file version or invalid file header in file > jdbc:h2:tcp//localhost:9092/~/test.data.db [90048-104]) > at > org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225) > at > org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) > at > org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:1377) > ... 5 more > Caused by: org.h2.jdbc.JdbcSQLException: Versión del archivo de base de > datos no soportada ó encabezado de archivo invalido en archivo > jdbc:h2:tcp//localhost:9092/~/test.data.db > Unsupported database file version or invalid file header in file > jdbc:h2:tcp//localhost:9092/~/test.data.db [90048-104] > at org.h2.message.Message.getSQLException(Message.java:103) > at org.h2.message.Message.getSQLException(Message.java:114) > at org.h2.message.Message.getSQLException(Message.java:77) > at org.h2.engine.Database.isTextStorage(Database.java:278) > at org.h2.engine.Database.open(Database.java:537) > at org.h2.engine.Database.<init>(Database.java:211) > at org.h2.engine.Engine.openSession(Engine.java:57) > at org.h2.engine.Engine.openSession(Engine.java:126) > at org.h2.engine.Engine.getSession(Engine.java:109) > at org.h2.engine.Session.createSession(Session.java:309) > at > org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:251) > at org.h2.engine.SessionRemote.createSession(SessionRemote.java:229) > at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111) > at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95) > at org.h2.Driver.connect(Driver.java:54) > at > org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) > at > org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) > at > org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247) > at > org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221) > ... 7 more > > This database was created with the same JAR that GeoServer through the > console. > With JDBC through TCP I can connect without problem > > Class.forName("org.h2.Driver"); > Connection conn = > DriverManager.getConnection("jdbc:h2:tcp://localhost:9092/~/test", "", ""); > conn.createStatement().executeUpdate("CREATE TABLE BORRAR(id int);"); > conn.close(); > > Thanks! > Ezequiel. > > ------------------------------------------------------------------------------ > Throughout its 18-year history, RSA Conference consistently attracts the > world's best and brightest in the field, creating opportunities for > Conference > attendees to learn about information security's most important issues > through > interactions with peers, luminaries and emerging and established companies. > http://p.sf.net/sfu/rsaconf-dev2dev > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > |
From: mmassigoge <mma...@gm...> - 2010-01-22 18:56:55
|
Hi, it don't seems to connect through TCP because is blocking the database, I think it works as embedded.. other options? -- View this message in context: http://n2.nabble.com/connect-geotools-with-H2-database-tp4435694p4441769.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |