请教各位大富翁JSP中怎么使用事务? ( 积分: 100 )

  • 主题发起人 主题发起人 chen4765654
  • 开始时间 开始时间
C

chen4765654

Unregistered / Unconfirmed
GUEST, unregistred user!
请问大富翁们怎么在JSP中使用事务,数据库是ACCESS和MSSQL2000
我用以下代码总是报错(以下代码使用的是ACCESS)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:JspDataSource","","");
Statement stmt = conn.createStatement();
conn.setAutoCommit(false);
sql="INSERT INTO VOTE VALUES('"+userid+"',"+level+")";
stmt.executeUpdate(sql);
conn.commit();
stmt.close();
conn.close();
错误提示:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver]现在无法设置属性
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.web.vote_jsp._jspService(vote_jsp.java:104)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]现在无法设置属性
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLSetConnectOption(JdbcOdbc.java:5115)
sun.jdbc.odbc.JdbcOdbcConnection.setAutoCommit(JdbcOdbcConnection.java:651)
org.apache.jsp.web.vote_jsp._jspService(vote_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
 
请问大富翁们怎么在JSP中使用事务,数据库是ACCESS和MSSQL2000
我用以下代码总是报错(以下代码使用的是ACCESS)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:JspDataSource","","");
Statement stmt = conn.createStatement();
conn.setAutoCommit(false);
sql="INSERT INTO VOTE VALUES('"+userid+"',"+level+")";
stmt.executeUpdate(sql);
conn.commit();
stmt.close();
conn.close();
错误提示:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver]现在无法设置属性
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.web.vote_jsp._jspService(vote_jsp.java:104)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]现在无法设置属性
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLSetConnectOption(JdbcOdbc.java:5115)
sun.jdbc.odbc.JdbcOdbcConnection.setAutoCommit(JdbcOdbcConnection.java:651)
org.apache.jsp.web.vote_jsp._jspService(vote_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
 
ACCESS 不行的,MSSQL2000要驱动
 
同意goddy。
 
接受答案了.
 
没有加异常处理,放在try{1}catch(SQLException e){}1内,先捕捉异常,看报什么错误。
 
后退
顶部