读书人

jsp连接Mysql数据库出现有关问题

发布时间: 2012-01-15 22:57:49 作者: rapoo

求助:jsp连接Mysql数据库出现问题,,,,,,
jsp连接Mysql数据库出现问题。

我的测试程序是:

import java.io.*;
import java.sql.*;

public class DbUtil {
static String driverName= "com.mysql.jdbc.Driver ";
static String dbUrl= "jdbc:mysql:// ";
static String user = "root ";
static String password = "12345678 ";

public DbUtil() { }

public static java.sql.Connection connectToDb(String hostName, String databaseName)throws Exception
{
Connection connection=null;
String connName = dbUrl + hostName+ ":3306 "+ "/ "+databaseName;
Class.forName(driverName).newInstance();
connection = DriverManager.getConnection(connName,user,password);
System.out.print( "Connect to DB OK... ");
return connection;

}

public static java.sql.Connection connectToDb(String databaseName)throws Exception{
return(connectToDb( "localhost ", databaseName));
}

public static java.sql.Connection connectToDb()throws Exception{
return(connectToDb( "localhost ", "addressbook "));
}

public static void main(String[] args)throws Exception{
try{
DbUtil db = new DbUtil();
db.connectToDb();
}catch(Exception e){
e.printStackTrace();
}
}

}

运行时出现如下错误:

java.sql.SQLException: 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(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at addressbook.model.DbUtil.connectToDb(DbUtil.java:25)
at addressbook.model.DbUtil.connectToDb(DbUtil.java:36)
at addressbook.model.DbUtil.main(DbUtil.java:42)


** END NESTED EXCEPTION **


at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:699)
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(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at addressbook.model.DbUtil.connectToDb(DbUtil.java:25)
at addressbook.model.DbUtil.connectToDb(DbUtil.java:36)
at addressbook.model.DbUtil.main(DbUtil.java:42)


[解决办法]
我在网上找了半天,试了N种方法,就是这句话一切都搞好了,希望碰到同样错误的人有所帮助 "mysql> set password for user1@ "localhost "=old_password( 'yourPassword '); "
[解决办法]
OLD_PASSWORD(str)

OLD_PASSWORD() was added to MySQL when the implementation of PASSWORD() was changed to improve security. OLD_PASSWORD() returns the value of the old (pre-4.1) implementation of PASSWORD(), and is intended to permit you to reset passwords for any pre-4.1 clients that need to connect to your version 5.0 MySQL server without locking them out.

原来是4.1之前客户端访问5.0服务端所用的password()方法

[解决办法]
呵呵


前几天做php的遇到过

也是这样解决的 就是一个加密机制不同

读书人网 >Java Web开发

热点推荐