【发布时间】:2014-02-06 02:43:28
【问题描述】:
我正在尝试对数据库做一些事情并且失败得很惨......请帮助!
这是我的代码,直到出现 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
现在,我正在运行应该在端口 7001 上创建数据库的 Weblogic 服务器。我注意到,如果我选择一个随机端口号,我得到的错误告诉我它被“拒绝”。事实并非如此——它被接受了……只是没有回应。
另外,在这一行:
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.
所以,它似乎存在,那么……
【问题讨论】:
-
我注意到即使我将 URL 显式更改为读取,此问题仍然存在,例如 jdbc:derby://localhost:7001/LF_JHU_Derby1;所以......网络在那里,但与数据库的连接不起作用......大概是因为它找不到它。但为什么呢?
-
Derby 网络服务器可能会将消息放入其 derby.log 文件中。你看过那里吗?