JiveJdon3.0 為何連不上MySQL 資料庫?

bolaila發表於2005-02-28
我看了幾天這個版本的有關資料庫連線的原始碼,但是仍未能解決空指標的問題,真無奈v=v !
希望各位指點:
經測試:jive 中的連線資料庫程式碼都是OK 的,但就是連線不上資料庫。
下面是我的測試程式碼:
package myCom.test;

import java.io.*;
import myCom.util.XMLParse;

import java.sql.*;
import java.util.*;

public class xmlTest
{
public static void main(String[] args)
{
Connection[] connPool = null;
Statement stmt = null;
ResultSet rst = null;
try
{
XMLParse parse = new XMLParse("E:\\javaSample\\DataAccess\\XMLFileParse\\jive.xml");
//parse.updateElement("root.one.a.b","one text");

String url = parse.getElementText("jive.database.defaultProvider.serverURL");
String driver = parse.getElementText("jive.database.defaultProvider.driver");
String userName = parse.getElementText("jive.database.defaultProvider.username");
String password = parse.getElementText("jive.database.defaultProvider.password");
//String minConn = parse.getElementText("jive.database.defaultProvider.minConnections");
//String maxConn = parse.getElementText("jive.database.defaultProvider.maxConnections");
System.out.println ("driver:"+driver+"\n url"+url+"\n userName:"+userName+"\n password :"+password);
java.util.Date now = new java.util.Date();
int loop = 5;
connPool = new Connection[5];
for (int i = 0; i<loop; i++)
{
try
{
Class.forName(driver).newInstance();
// Connection cc = DriverManager.getConnection(url,userName,password);
connPool = DriverManager.getConnection(url,userName,password);

// System.out.println(now.toString() + " Opening connection " + String.valueOf(i) +
// " " + cc.toString() + ":");
System.out.println(now.toString() + " Opening connection " + String.valueOf(i) +
" " + connPool.toString() + ":");

}
catch (ClassNotFoundException cnfe)
{
System.out.println ("Exception for createConn()::");
cnfe.printStackTrace();
throw new SQLException(cnfe.getMessage());
}
}

//one
String sq="select * from jiveid";
stmt = connPool[1].createStatement();
rst = stmt.executeQuery(sq);

while(rst.next())
{
System.out.println ("idType::"+rst.getInt("idType"));
System.out.println ("id::"+rst.getInt("id"));
}
System.out.println ("=====**************==========\n\n");
//two
String sql = "select * from jiveuser";
stmt = connPool[2].createStatement();
rst = stmt.executeQuery(sql);

while(rst.next())
{
System.out.println ("name::"+rst.getString("name"));
System.out.println ("userName::"+rst.getString("username"));
}
System.out.println ("=====**************==========\n\n");
for (int i = 0; i<loop; i++)
{
try
{
if(!connPool.isClosed())
{
System.out.println ("close the connetion:"+connPool.toString());
connPool.close();
}
}
catch (Exception ex)
{
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
輸出完全沒問題的,這也是JiveJdon3.0 使用的資料庫連線方法。
執行提示空指標異常,輸出的日誌記錄如下:
Attempt (1 of 5) failed to create new connections set at startup:
java.sql.SQLException: Communication failure during handshake. Is there a server running on 127.0.0.1:3306?
。。。。。
還望各位不惜指教,謝謝!

相關文章