0

For my current project I have to use HSQL-JDO. I am writting sample application to check how this work. If I am using HSQL with jdbc (without any orm) my code run fine. But with JDO I am getting "socket creation error"

[Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) entered [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) exited [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) entered [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) exited [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) entered [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) exited [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) entered [Server@187a84e4]: [Thread[main,5,main]]: checkRunning(false) exited JdbcOdbcDriver class loaded registerDriver: driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@a13f991] DriverManager.initialize: jdbc.drivers = null JDBC DriverManager initialized registerDriver: driver[className=org.hsqldb.jdbcDriver,org.hsqldb.jdbcDriver@44e06940] DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:8974/test_db") trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@a13f991] *Driver.connect (jdbc:hsqldb:hsql://localhost:8974/test_db) trying driver[className=org.hsqldb.jdbcDriver,org.hsqldb.jdbcDriver@44e06940] SQLState(08000) vendor code(-80) java.sql.SQLException: socket creation error at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.jdbcConnection.(Unknown Source) at org.hsqldb.jdbcDriver.getConnection(Unknown Source) at org.hsqldb.jdbcDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:78) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1158) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:444) at org.datanucleus.store.rdbms.RDBMSStoreManager.(RDBMSStoreManager.java:264)

Here is the code in main Server server = new Server(); server.setAddress("localhost"); server.setDatabaseName(0, "test_db"); server.setDatabasePath(0, "test_db"); server.setPort(8974); server.setTrace(true);

    Properties properties = new Properties();
    properties.setProperty("javax.jdo.PersistenceManagerFactoryClass","org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
    properties.setProperty("javax.jdo.option.ConnectionDriverName","org.hsqldb.jdbcDriver");
    properties.setProperty("javax.jdo.option.ConnectionURL","jdbc:hsqldb:hsql://localhost:8974/test_db");
    properties.setProperty("javax.jdo.option.ConnectionUserName","SA");
    properties.setProperty("javax.jdo.option.ConnectionPassword","");
    properties.setProperty("javax.jdo.option.ConnectionPassword","");

    properties.setProperty("datanucleus.autoCreateSchema","true");
    properties.setProperty("datanucleus.validateTables","false");
    properties.setProperty("datanucleus.validateConstraints","false");

    PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);

    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx=pm.currentTransaction();

    tx.begin();
    pm.makePersistent(new Session("aniruddha"));
    tx.commit();

    Query q = pm.newQuery("SELECT FROM "+Session.class.getName());

    List<Session> sessions = (List<Session>)q.execute();
    //Iterator<Session> iter = sessions.iterator();

    for(Session s : sessions){
        System.out.println(s.getSESSION_ID()+" : "+s.getSESSION_USERNAME());
    }

Here is the bean that I want to persist

@PersistenceCapable public class Session { private Session(){ // Default constructor required by jdo } public Session(String session_username){ SESSION_USERNAME = session_username; }

public long getSESSION_ID() {
    return SESSION_ID;
}
public String getSESSION_USERNAME() {
    return SESSION_USERNAME;
}
public void setSESSION_ID(long sESSION_ID) {
    SESSION_ID = sESSION_ID;
}
public void setSESSION_USERNAME(String sESSION_USERNAME) {
    SESSION_USERNAME = sESSION_USERNAME;
}


@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.INCREMENT)
private long SESSION_ID;
private String SESSION_USERNAME;

}

4
  • A google search for that exception and HSQL will give lots of information May 17, 2012 at 14:58
  • if I put connection string something like "jdbc:hsqldb:file:test_db". It works. But if connection string is something like "jdbc:hsqldb:hsql://localhost:8974/test_db" gives me "socket creation error"
    – Aniruddha
    May 18, 2012 at 11:59
  • It looks to be something wrong with my configuration. I did google, but nothing found that resolve problem yet.
    – Aniruddha
    May 18, 2012 at 12:04
  • Comment stackoverflow.com/questions/10637433/… works fine for me.
    – hadf
    Jul 31, 2013 at 20:16

1 Answer 1

0

If server mode doesn't work then you haven't started the HSQLDB server. Works for me with either form, either URL or file. I start a server from the command line exactly as per the HSQLDB docs.

With your API calls for Server, you seem to be missing calling "server.start()". Either way the problem is in HSQLDB server startup, not DataNucleus access.

1
  • Thanks for replying. My problem resolved. I wasn't starting server.
    – Aniruddha
    May 19, 2012 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.