当我尝试连接到MySQL数据库时遇到此问题。它告诉我这是错误的,我不知道为什么,因为它没有给我特定的错误。
这只是让我知道我在渔获物中所写的内容。 顺便说一句,我正在使用MySQL Connector / J版本5.1.47。
这是连接代码:
private class GetData extends AsyncTask<String,String,String> {
String msg = "";
//JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://" +
DbStrings.DATABASE_URL + "/" +
DbStrings.DATABASE_NAME;
@Override
protected void onPreExecute() {
ProgressTextView.setText("Connecting to Database...");
}
@Override
protected String doInBackground(String... params) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, DbStrings.USERNAME, DbStrings.PASSWORD);
stmt = conn.createStatement();
String sql = "SELECT * FROM zimmerstamm";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String Bemerkung = rs.getString("Bemerkung");
Double Zimmer = rs.getDouble("Zimmer");
fruitsMap.put(Bemerkung, Zimmer);
}
msg = "Process complete";
rs.close();
stmt.close();
conn.close();
} catch (SQLException connError) {
msg = "An exception was thrwon for JDBC.";
connError.printStackTrace();
} catch (ClassNotFoundException e) {
msg = "And exception was No class found.";
e.printStackTrace();
}