因此,下面的代码在 Eclipse 中有效,但在 CL 中无效。我认为它与 JDBC 连接器有关,但我不确定。它没有给我任何错误,只是没有执行。例如,它甚至不会打印“EDF”。有什么建议么?
//Connection conn = null;
String url = "jdbc:mysql://localhost/";
String db = "db";
String driver = "com.mysql.jdbc.Driver";
String table = "order_queue";
Connection conn = null;
// Upload trade data to order_queue table
try {
Class.forName(driver);
System.out.print("EDF");
try {
conn = DriverManager.getConnection(url+db,"root","");
Statement st = conn.createStatement();
String sql = "INSERT INTO " + table + " (name) VALUES("APPLE");
st.executeUpdate(sql);
conn.close();
} catch (SQLException s) {
s.printStackTrace();
orderMessage = "ERROR: Problem executing order. Please try again!";
}
} catch (ClassNotFoundException cnfe){
orderMessage = "ERROR: Problem connecting to OMS database. Contact technical support or try again later.";
}