我有以下代码,它没有到达 .setText("Successful") 语句,表明 drivermanager.getConnection statemenet 存在问题(我认为)。它从 net.sourceforge 中找到我正在使用的数据库驱动程序。但是没有抛出异常错误消息,没有任何反应:
String connectionurl = "jdbc:jtds:sqlserver://41.185.13.201; databaseName=Courses; user=*;Password=*;Persist Security Info=True;";
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(connectionurl);
textview7.setText("Successful");
// Create and execute an SQL statement that returns some data.
String SQL = "INSERT INTO Courses (CourseCode) VALUES ('INFO3002')";
Statement stmt = con.createStatement();
stmt.executeUpdate(SQL);
con.close();
}
catch (ClassNotFoundException e) {
textview7.setText("Could not find the database driver " + e.getMessage());
} catch (SQLException e) {
textview7.setText("Could not connect to the database " + e.getMessage());
}
catch (Exception e) {
//textview7.setText(e.getMessage());
}