一个数据库问题
近来遇到一个很奇怪的问题,就是更新一个教师表的信息的时候,如果只更新前三个字段,就没有出错;如果再加一个字段,就说语法错误.代码如下:
/////////修改教师信息
public boolean update_teacher(String id1,String id2,String name,String level,int dep_id)
{
conn=c.getConnection();
//String k="1";
boolean flag=false;
String sql="update teacher set teacherID='"+id2+"',name='"+name+"',departID='"+dep_id+"',level='"+level+"' where teacherID=?"; // 加上红色的代码就会出错
try{
preparedstatement = conn.prepareStatement(sql);
preparedstatement.setString(1,id1);
preparedstatement.executeUpdate();
conn.commit();
flag=true;
}catch ( SQLException e )
{
e.printStackTrace();
try
{
//回滚操作.
conn.rollback();
}
catch ( SQLException e1 )
{
e1.printStackTrace();
}
}
//关闭资源.
finally
{
try
{
if(preparedstatement!=null)
{
preparedstatement.close();
}
if(conn!=null)
{
conn.close();
}
}
catch ( SQLException e1 )
{
e1.printStackTrace();
}
}
return flag;
}
异常如下:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] UPDATE 语句的语法错误。
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
at test.admin.teach_DAO.update_teacher(teach_DAO.java:247)
at test.admin.Modi_teach.doPost(Modi_teach.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:566)
麻烦各位高手能给个解答,问题究竟出在哪里?
ps:我用的是access数据库,教师表有五个字段,分别是teacherID,name,departID,psw,level
[此贴子已经被作者于2006-12-8 10:40:16编辑过]