Java中Access 数据库不能通过 stmt.executeUpdate更新记录?(50分)

  • 主题发起人 主题发起人 mycwcgr_bak
  • 开始时间 开始时间
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);
}
}
 
在NTFS格式下,可能是文件或者目录设成只读,看一下普通用户,比如guestd的访问权限
 
Java中Access 数据库能通过 stmt.executeUpdate更新记录,你把ACCESS关掉运行一下试试
 
既然是报Insert into 语法错,你把SQL代码直接在ACCESS中运行呢?错误否?如果在ACCESS中运行也是错的,那么就和JDBC没什么关系了
 
多人接受答案了。
 
后退
顶部