我有一个小问题jdbc.odbc.JdbcOdbcDriver
。
它给了我以下错误:
java.sql.SQLException: Driver does not support this function
编码:
saverec.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saverecclick = 1;
if (saverecclick == 1) {
try {
field2.setEnabled(false);
field3.setEnabled(false);
field4.setEnabled(false);
field5.setEnabled(false);
field6.setEnabled(false);
table.setEnabled(true);
MainFrame();
String myDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String myUrl = "jdbc:odbc:DLFishHunter";
con = DriverManager.getConnection("jdbc:odbc:DLFishHunter");
stmt = con.createStatement();
String query = " insert into Data (User, Datum, Location, Kind, Size , Bait)" + " values (?, ?, ?, ?, ?, ?)";
Calendar calendar = Calendar.getInstance();
java.sql.Date startDate = new java.sql.Date(calendar.getTime().getTime());
PreparedStatement preparedStmt = con.prepareStatement(query);
String suser = field0.getSelectedItem().toString();
preparedStmt.setString(1, suser);
preparedStmt.setDate(2, startDate);
preparedStmt.setString(3, field3.getText());
kinddb = field4.getSelectedItem().toString();
preparedStmt.setString(4, kinddb);
preparedStmt.setString(5, field5.getText());
preparedStmt.setString(6, field6.getText());
frame.dispose();
preparedStmt.execute();
try {
Class.forName(myDriver);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex);
}
Connection con = (Connection) DriverManager.getConnection(myUrl, "root", "");
} catch (SQLException ex) {
Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
问题出在上面的代码中。