无法连接到数据库 - java.sql.SQLNonTransientConnectionException

时间:2014-02-06 02:43:29

标签: java database derby

我正在尝试用数据库做一些事情并且悲惨地失败......请帮忙!

这是我的代码,直到SQLNonTransientConnectionException为止:

public class UFTest {

   public static void main(String[] args) throws ClassNotFoundException, SQLException{ 

   Hashtable ht = new Hashtable();
   ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
   ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
   ht.put(Context.SECURITY_PRINCIPAL, "User");
   ht.put(Context.SECURITY_CREDENTIALS, "pw");
System.out.println("cx/ht succesful");       
   Context cx = null;
   Connection con = null;
   Statement stmt = null;
   ResultSet rs = null;
   String source = "jdbc/LF_JHU_DERBY";
   File file = new File("Student_List.txt"); 

   try{
System.out.println("try entered");           
       cx = new InitialContext(ht);
System.out.println("cx created"); 
       Class.forName("org.apache.derby.jdbc.ClientDriver");
       DriverManager.getConnection("jdbc:derby://localhost:7001/LF_JHU_Derby;create=true","User", "pw");

此时我明白了:

java.sql.SQLNonTransientConnectionException: Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes.  The connection has been terminated.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at randomtests.UFTest.main(UFTest.java:38)
Caused by: org.apache.derby.client.am.DisconnectException: Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes.  The connection has been terminated.
at org.apache.derby.client.net.Reply.fill(Unknown Source)
at org.apache.derby.client.net.Reply.ensureALayerDataInBuffer(Unknown Source)
at org.apache.derby.client.net.Reply.readDssHeader(Unknown Source)
at org.apache.derby.client.net.Reply.startSameIdChainParse(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.readExchangeServerAttributes(Unknown Source)
at org.apache.derby.client.net.NetConnection.readServerAttributesAndKeyExchange(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowServerAttributesAndKeyExchange(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
... 4 more

现在,我正在运行Weblogic服务器,在该服务器上应该在端口7001上创建数据库。我注意到,如果我选择一个随机端口号,我得到的错误告诉我它被“拒绝”。这不是这种情况 - 它被接受......只是没有回应。

另外,在以下行:

cx = new InitialContext(ht);

我得到以下内容:

Problem creating dummy orb: org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 203  completed: No

,尽管使用谷歌搜索,不明白(当然不知道如何解决)。我不知道问题是否有关......请帮助!

这是来自命令行(关于创建数据库):

ij> CONNECT 'jdbc:derby:LF_JHU_Derby;create=true';
CREATE TABLE STUDENT ( FIRST_NAME varchar(40), LAST_NAME varchar(40) , SSN char(11) ,          EMAIL varchar(40), ADDRESS varchar(40), USERID varchar(8) , PASSWORD varchar(8) );
quit;ij> 0 rows inserted/updated/deleted

然后,测试:

ij> CONNECT 'jdbc:derby:LF_JHU_Derby;create=true';
WARNING 01J01: Database 'LF_JHU_Derby' not created, connection made to existing database       instead.

所以,它似乎存在,然后......

1 个答案:

答案 0 :(得分:0)

如果你有

@Transient
在您使用此方法的顶部的

注释,尝试删除该注释,然后继续......