日期:2014-05-18  浏览次数:20763 次

请教jsp连接sql2000的一个问题````
<%
String   userid=codeToString(request.getParameter( "T1 "));
String   password=codeToString(request.getParameter( "T2 "));
String   bpassword=codeToString(request.getParameter( "T3 "));
String   question=codeToString(request.getParameter( "T4 "));
String   answer=codeToString(request.getParameter( "T5 "));
String   email=codeToString(request.getParameter( "T6 "));
String   IDE=codeToString(request.getParameter( "T7 "));
String   username=codeToString(request.getParameter( "T8 "));
%>
<%
String   sqlString=null;
sqlString= "insert   into   user(UserID,Password,bpassword,question,answer,email,IDE,username) "+ "values( ' "+userid+ " ', ' "+password+ " ', ' "+bpassword+ " ', ' "+question+ " ', ' "+answer+ " ', ' "+email+ " ', ' "+IDE+ " ', ' "+username+ " ') ";
%>
<%
try
{
Connection   con;
Statement   sql;
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
con=DriverManager.getConnection( "jdbc:odbc:mnjiesql ");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql.executeUpdate(sqlString);
con.close();
}
catch(SQLException   e1)
{
out.print( "SQL异常! ");
}
%>
那个地方写错了``???
什么错误都没有报就是显示出了`   SQL异常

------解决方案--------------------
Connection con=null;
Statement sql=null;
------解决方案--------------------
values前后有没有加空格
------解决方案--------------------
<%
String sqlString=null;
sqlString= "insert into user(UserID,Password,bpassword,question,answer,email,IDE,username) "+ "values( ' "+userid+ " ', ' "+password+ " ', ' "+bpassword+ " ', ' "+question+ " ', ' "+answer+ " ', ' "+email+ " ', ' "+IDE+ " ', ' "+username+ " ') ";
%>
(UserID,Password,bpassword,question,answer,email,IDE,username)《《 "+ "》》values
为什么要加上“+” 是什么意思呀?
------解决方案--------------------
e1你说这是什么意思,崩溃了,麻烦去了解一下对象的概念
------解决方案--------------------
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
的异常是CLASSNOTFOUNDEXCEPTION异常.而不是SQLEXCEPTION异常.最后每条语句都分开捕捉异常
虽然麻烦点.但是对于以后的调试大有好处的.可以迅速定位错误发生点嘛.
同时,从request传递过来的String值还是先进行重新编码比较好.可以避免一下很奇怪的错误
接下来还有问题,请等待高手了.