首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp与mysql连接出错了不知道是不是驱动的有关问题

2012-01-15 
jsp与mysql连接出错了不知道是不是驱动的问题/**Createdon2007-4-20**Tochangethetemplateforthisgenerate

jsp与mysql连接出错了不知道是不是驱动的问题
/*
  *   Created   on   2007-4-20
  *
  *   To   change   the   template   for   this   generated   file   go   to
  *   Window>Preferences>Java>Code   Generation>Code   and   Comments
  */
package   org.pan.util;

/**
  *   @author   new
  *
  *   To   change   the   template   for   this   generated   type   comment   go   to
  *   Window>Preferences>Java>Code   Generation>Code   and   Comments
  */
import   java.sql.*;  

public   class   DBTest{  
public   static   void   main(String[]   args)   {  
String   driver   =   "org.gjt.mm.mysql.Driver ";
String   url   =   "jdbc:mysql://localhost:3306/business ";
String   user   =   "root ";  
String   password   =   "aa ";  
try   {
Class.forName(driver);  
Connection   conn   =   DriverManager.getConnection(url,   user,   password);  
if(!conn.isClosed())  
System.out.println( "数据库连接成功! ");  
conn.close();  
}  
catch(ClassNotFoundException   e)   {  
System.out.println( "找不到驱动程序 ");  
e.printStackTrace();  
}  
catch(SQLException   e)   {  
e.printStackTrace();  
}  
}  
}

出错信息

java.sql.SQLException:   Communication   failure   during   handshake.   Is   there   a   server   running   on   localhost:3306?
at   org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:327)
at   org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
at   org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
at   org.gjt.mm.mysql.Driver.connect(Driver.java:167)
at   java.sql.DriverManager.getConnection(Unknown   Source)
at   java.sql.DriverManager.getConnection(Unknown   Source)
at   org.pan.util.DBTest.main(DBTest.java:25)


[解决办法]
net start mysql

热点排行