找不到合适的司机

时间:2012-12-22 04:03:26

标签: java mysql java-ee tomcat6 eclipse-juno

我收到了错误..

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at pack.ConnectionFactory.getConnect(ConnectionFactory.java:37)
String DriverClass = "com.mysql.jdbc.Driver";
static String url =     "jdbc:mysql://localhost:3306/dbqwe";    

使用J2SE1.5,TOMCAT 6.0.36,MYSQL 5.5 SERVER和ECLIPSE JUNO。

tried with mysql-connector-java-5.1.18-bin
mysql-connector-java-5.1.22.jar
mysql-connector-java-5.1.2.jar
mysql-connector-java-3.1.7-bin.jar
ojdbc14.jar

将它们放在

web-inf/lib, tomcat lib

eclipse/jre/lib

将jar文件添加到java构建路径中......

知道我哪里出错了?

4 个答案:

答案 0 :(得分:0)

您需要在username中提供passwordString url

static String url = "jdbc:mysql://localhost:3306/dbqwe?user=usrHere&password=passHERE"; 

有关将JAVAMySQL联系起来的泥潭信息,请访问以下链接:

PS:您可以发布整个代码吗?

答案 1 :(得分:0)

你注册了你的司机吗?在DriverManager.getConnection之前应该有

Class.forName("com.mysql.jdbc.Driver");

DriverManager.registerDriver(new com.mysql.jdbc.Driver());

答案 2 :(得分:0)

    public class ConnectionFactory 
    {
      String DriverClass = "com.mysql.jdbc.Driver";
      static String url = "jdbc:mysql://localhost:3306/dbb";
       static String Userid = "root";
     static String Pwd = "pswd";
      StringBuffer output = new StringBuffer();
    ConnectionFactory cf = new ConnectionFactory(); 
     private ConnectionFactory()
{ try{ Class.forName(DriverClass);
     //output.append("Driver Installation Successful");
     System.out.println("Driver Installed"); }
 catch (ClassNotFoundException e)
    {e.printStackTrace();
    output.append("Driver Installation Failed");  }}
  public  static Connection getConnect() throws SQLException 
  {Connection con = DriverManager.getConnection(url, Userid, Pwd);
    return con;}}

答案 3 :(得分:0)

如果在$ {CATALINA_HOME} /conf/server.xml中取消注释此行:

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />

将其更改为:

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false" />

这会将Tomcat返回到6.0.35之前的版本,它在$ {CATALINA_HOME} / lib

中正确注册了类型4 JDBC驱动程序