1

我收到一个错误..

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

4 回答 4

0

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

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

或者

DriverManager.registerDriver(new com.mysql.jdbc.Driver());
于 2012-12-22T04:20:23.180 回答
0

您需要在您username的.passwordString url

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

有关与 连接JAVA的更多信息MySQL,请访问以下链接:

PS:你能发布你的整个代码吗?

于 2012-12-22T04:06:12.673 回答
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;}}
于 2012-12-24T06:37:47.437 回答
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 驱动程序

于 2013-08-06T21:15:18.483 回答