最近在做一些数据库连接方面的测试的时候,总是会出现各种各样的问题,现将示例代码写出:
import com.mysql.jdbc.*;
import java.sql.*;
public class TestMySQL
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/BookDB?useUnicode=true&characterEncoding=GB2312", "user", "password");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
再将执行后所产生的错误如下:
Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream
** BEGIN NESTED EXCEPTION **
java.io.IOException
MESSAGE: Unexpected end of input stream
STACKTRACE:
java.io.IOException: Unexpected end of input stream
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1096)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:626)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562)
at com.mysql.jdbc.Connection.<init>(Connection.java:491)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestMySQL.main(TestMySQL.java:16)
** END NESTED EXCEPTION **
哪位高手有时间指点一二啊,急啊.不甚感激之至啊.谢谢!
posted @
2007-04-25 11:30 竹笛月影 阅读(305) |
评论 (0) |
编辑 收藏