我正在尝试连接Android中的MySQL:
try{
String url = "jdbc:mysql://192.168.0.105:3306/qrdb";
String username = "root";
String password = "****";
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
String sqlCommand = "CREATE TABLE items (Id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20), price INT)";
try (Connection conn = DriverManager.getConnection(url, username, password)){
Statement statement = conn.createStatement();
// создание таблицы
statement.executeUpdate(sqlCommand);
Log.i("mytag","Database has been created!");
}
}
catch (SQLException ex) {
// handle any errors
Log.i("mytag","SQLException: " + ex.getMessage());
Log.i("mytag","SQLState: " + ex.getSQLState());
Log.i("mytag","VendorError: " + ex.getErrorCode());
}
catch(Exception ex){
Log.i("mytag","Connection failed...");
Log.i("mytag", "" + ex);
}
引发异常:
java.lang.UnsupportedOperationException
已安装MySQL Connector / J 8.0。在通常的Java项目中,一切正常。