当前位置: 技术问答>java相关
JSP新手100分求助!
来源: 互联网 发布时间:2015-01-30
本文导语: 刚开始学JSP,问题多多。下面是我的BEAN,executeQuery没问题,但executeUpdate总有问题,说INSERT INTO 语句的语法错误。 public class dbfiles{ String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String sConnStr = "jdbc:odbc:files"; Connection c...
刚开始学JSP,问题多多。下面是我的BEAN,executeQuery没问题,但executeUpdate总有问题,说INSERT INTO 语句的语法错误。
public class dbfiles{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:files";
Connection conn = null;
ResultSet rs = null;
public dbfiles() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("dbfiles(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,"maza","157268");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
conn.commit();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public String executeUpdate(String sql)
{
try{
conn=DriverManager.getConnection(sConnStr,"maza","157268");
Statement stmt =conn.createStatement();
stmt.executeUpdate(sql);
conn.commit();
return "yes";
}
catch(SQLException ex)
{
System.err.println("executeUpdate:" + ex.getMessage());
return "no" + (String)ex.getMessage() + sql;
}
}
}
SQL语句是:
表中字段顺序如上,但后面还有两个字段没写,可以为NULL,是ACCESS2K的。
请前辈给看看,我会补分的。
public class dbfiles{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:files";
Connection conn = null;
ResultSet rs = null;
public dbfiles() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("dbfiles(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,"maza","157268");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
conn.commit();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public String executeUpdate(String sql)
{
try{
conn=DriverManager.getConnection(sConnStr,"maza","157268");
Statement stmt =conn.createStatement();
stmt.executeUpdate(sql);
conn.commit();
return "yes";
}
catch(SQLException ex)
{
System.err.println("executeUpdate:" + ex.getMessage());
return "no" + (String)ex.getMessage() + sql;
}
}
}
SQL语句是:
表中字段顺序如上,但后面还有两个字段没写,可以为NULL,是ACCESS2K的。
请前辈给看看,我会补分的。
|
重新贴: "date"是 Access 的关键字!
String sql="insert into tabs (neirong,jiezhi,shuliang,[date],shiyong) values " +
"('neirong','jiezhi','shuliang',date(),'')";
或:
String sql="insert into tabs (neirong,jiezhi,shuliang,[date],shiyong) values " +
"('neirong','jiezhi','shuliang',date,'')";
String sql="insert into tabs (neirong,jiezhi,shuliang,[date],shiyong) values " +
"('neirong','jiezhi','shuliang',date(),'')";
或:
String sql="insert into tabs (neirong,jiezhi,shuliang,[date],shiyong) values " +
"('neirong','jiezhi','shuliang',date,'')";