对于我目前的项目,我必须使用HSQL-JDO。我正在写示例应用程序来检查这个工作。如果我使用HSQL与jdbc(没有任何orm)我的代码运行良好。但随着JDO我收到 “套接字创建错误”JDO - datanucleus - HSQL错误
[[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited JdbcOdbcDriver class loaded registerDriver: driver[className=sun.jdbc.odbc.JdbcOdbcDriver,[email protected]] DriverManager.initialize: jdbc.drivers = null JDBC DriverManager initialized registerDriver: driver[className=org.hsqldb.jdbcDriver,[email protected]] DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:8974/test_db") trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,[email protected]] *Driver.connect (jdbc:hsqldb:hsql://localhost:8974/test_db) trying driver[className=org.hsqldb.jdbcDriver,[email protected]] 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)
这里是主 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());
}
下面的代码是我要坚持
@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;
}
如果我将连接字符串放在“jdbc:hsqldb:file:test_db”之类的地方,Google搜索该异常和HSQL将提供大量信息 – DataNucleus
。有用。但是如果连接字符串类似于“jdbc:hsqldb:hsql:// localhost:8974/test_db”给我“套接字创建错误” – Aniruddha
它看起来是我的配置有问题。我没有谷歌,但没有发现解决问题。 – Aniruddha