public void actionPerformed(ActionEvent arg0) {
String departurecity = depcity.getText();
String depdate = dt.getText();
String arrivalcity = ac.getText();
String arrivaldate = dtar.getText();
String cabinclass = ccc.getText();
String seats = sts.getText();
String price = prc.getText();
try {
Connection connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:8080/airblue", "root", "");
java.sql.Statement st = connection.createStatement();
String query = "INSERT INTO flight values('" + departurecity + "','" + depdate + "','" + arrivalcity + "','" +
arrivaldate + "','" +cabinclass + "','" + seats +"','"+price+ "')";
Statement sta = (Statement) ((java.sql.Connection) connection).createStatement();
int x = ((java.sql.Statement) sta).executeUpdate(query);
JOptionPane.showMessageDialog(btnNewButton,
"done");
connection.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
这是我的连接代码的一小部分,我尝试了许多解决方案,但没有一个对我有任何解决此问题的解决方案?