/*
* 添加试题
*/
static void addQst(Qst q) throws ClassNotFoundException, SQLException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:db";
Connection con=DriverManager.getConnection(url,"HP","aa");
Statement stmt=con.createStatement();
stmt.executeUpdate("INSERT INTO "
+q.getType()+
" (content,answer,difficulty,score,mytime) VALUES ('"+q.getContent()+"','"+q.getAnswer()+"','"+q.getDiff()+"',"+q.getScore()+","+q.getMyTime()+")");
con.close();
}
/*
* 删除试题
*/
static void deleteQst(Qst q) throws ClassNotFoundException, SQLException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:db";
Connection con=DriverManager.getConnection(url,"HP","aa");
Statement stmt=con.createStatement();
stmt.executeUpdate("DELETE FROM "+q.getType()+" WHERE ID="+q.getId());
}
其中Qst是我建的一个类,存放Qst的一些属性...ID是自动编号的...
因为代码太多,我就只把删除和添加的部分放上来