当尝试连接到mysql时,我总是收到此错误:
java.sql.SQLException:找不到适合localhost测试的驱动程序
我已经包括mysql-connector.jar
在/WEB-INF/lib
我的应用程序.我需要配置什么才能使其工作?我需要添加一些东西web.xml
吗?我没有使用appengine.
这是我在服务器中的代码:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)