M
mycwcgr_bak
Unregistered / Unconfirmed
GUEST, unregistred user!
Java中Access 数据库不能通过 stmt.executeUpdate更新记录?
下面的程序中stmt.executeUpdate(sql);注释到可以正常增加记录,如果不注释的话将出错
错误信息为Add record java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句的语法错误。
但为什么下面的语句... rs.insertRow();... 能够正确的插入记录呢?
package server_process;
public class process_add_projectinfo extends process_base {
data_add_projectinfo data_client;
public process_add_projectinfo(Socket socket, data_add_projectinfo data_base) {
super(socket,data_base);
data_client=data_base;
if (valid_permission_project_of_write()) {
String sql;
sql="insert into project_info (title,content,from) values ("
+"'"+data_client.myprojectinfo.title+"'" +","
+"'"+data_client.myprojectinfo.content+"'" +","
+"'"+data_client.myprojectinfo.from+"'"
+")";
String sql_new="select * from project_info";
System.out.println(sql);
try {
//stmt.executeUpdate(sql);
ResultSet rs=stmt.executeQuery(sql_new);
rs.moveToInsertRow();
rs.updateString("title",data_client.myprojectinfo.title);
rs.updateString("content",data_client.myprojectinfo.content);
rs.updateString("from",data_client.myprojectinfo.from);
rs.insertRow();
}catch (Exception e ){
System.out.println("Add record "+e );
}
}
}
}
package server_process;
public class process_base {
PrintWriter send_to_client=null;
Connection conn=null;
Statement stmt=null;
data_base_client_to_server inputdata;
String sql;
process_base(Socket socket, data_base_client_to_server inputdata) {
try {
send_to_client=new PrintWriter( new OutputStreamWriter(socket.getOutputStream()) );
this.inputdata=inputdata;
Class.forName(comm_availble.class_forname);
conn=DriverManager.getConnection(comm_availble.url,comm_availble.user,comm_availble.password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}catch (Exception e){
System.out.println("server_process "+e);
}
}
下面的程序中stmt.executeUpdate(sql);注释到可以正常增加记录,如果不注释的话将出错
错误信息为Add record java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句的语法错误。
但为什么下面的语句... rs.insertRow();... 能够正确的插入记录呢?
package server_process;
public class process_add_projectinfo extends process_base {
data_add_projectinfo data_client;
public process_add_projectinfo(Socket socket, data_add_projectinfo data_base) {
super(socket,data_base);
data_client=data_base;
if (valid_permission_project_of_write()) {
String sql;
sql="insert into project_info (title,content,from) values ("
+"'"+data_client.myprojectinfo.title+"'" +","
+"'"+data_client.myprojectinfo.content+"'" +","
+"'"+data_client.myprojectinfo.from+"'"
+")";
String sql_new="select * from project_info";
System.out.println(sql);
try {
//stmt.executeUpdate(sql);
ResultSet rs=stmt.executeQuery(sql_new);
rs.moveToInsertRow();
rs.updateString("title",data_client.myprojectinfo.title);
rs.updateString("content",data_client.myprojectinfo.content);
rs.updateString("from",data_client.myprojectinfo.from);
rs.insertRow();
}catch (Exception e ){
System.out.println("Add record "+e );
}
}
}
}
package server_process;
public class process_base {
PrintWriter send_to_client=null;
Connection conn=null;
Statement stmt=null;
data_base_client_to_server inputdata;
String sql;
process_base(Socket socket, data_base_client_to_server inputdata) {
try {
send_to_client=new PrintWriter( new OutputStreamWriter(socket.getOutputStream()) );
this.inputdata=inputdata;
Class.forName(comm_availble.class_forname);
conn=DriverManager.getConnection(comm_availble.url,comm_availble.user,comm_availble.password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}catch (Exception e){
System.out.println("server_process "+e);
}
}