我有一个奇怪的问题。 我在 AppEngine 上使用 GWT,我想创建连接到 MySql 的 RPC。我整天都坐在上面。这是我对 RPC 方法的实现:
java.sql.Connection con = null;
public DataBaseServiceImpl() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.print("bladd..");
e.printStackTrace();
}
String url ="jdbc:mysql://localhost:8806/base";
try {
con = DriverManager.getConnection( url,"root", "");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public ArrayList<String[]> getTables(int idUser) throws SQLException {
Statement st = con.createStatement();
ResultSet retrive = st.executeQuery("query");
ArrayList<String[]> result = new ArrayList<String[]>();
while(retrive.next())
{
String[] s = new String[2];
int theInt= retrive.getInt("ID__TABLE");
String str = retrive.getString("LABEL");
s[0]=Integer.toString(theInt);
s[1]=str;
result.add(s);
}
return result;
}
我有这个错误:
java.sql.SQLException: Unable to initialize driver properties due to java.lang.IllegalAccessException: Class com.google.appengine.tools.development.agent.runtime.Runtime can not access a member of class com.mysql.jdbc.ConnectionPropertiesImpl with modifiers "private"
我不知道这是什么。 有人可以帮助我吗?
问候。
最佳答案
底线是你的代码真的很乱。有许多违反良好编码习惯的行为。
从你包含的代码来看,这一行永远不会被执行:
con = DriverManager.getConnection( url,"root", "");
所以没有连接到你的数据库。你的异常是否表明这一行
Statement st = con.createStatement();
是什么问题?
关于java - GWT中如何连接MySql? (应用引擎),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17572396/