【发布时间】:2012-01-20 12:53:25
【问题描述】:
当尝试连接到 mysql 时,我总是得到这个错误:
java.sql.SQLException: 找不到适合 localhost 测试的驱动程序
我已经在我的应用程序的/WEB-INF/lib 中包含了mysql-connector.jar。我还需要配置什么才能使其工作?我需要在web.xml 中添加一些内容吗?我没有使用应用引擎。
这是我在服务器中的代码:
package com.mysql.server;
import java.sql.Connection;
import java.sql.DriverManager;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mysql.client.ConnDb;
public class ConnDbImpl extends RemoteServiceServlet implements ConnDb {
public Connection con;
@Override
public String tryConn() {
try{
String host = "localhost";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "pwd";
Class.forName(driver).newInstance();
con = DriverManager.getConnection(host+db, user, pass);
return "Connected to Database";
} catch(Exception ex) {
return ex.toString();
}
}
}
【问题讨论】: