当前位置: 代码迷 >> Java Web开发 >> 一个数据库问题――请教(急啊!!)
  详细解决方案

一个数据库问题――请教(急啊!!)

热度:136   发布时间:2006-11-16 22:18:51.0
一个数据库问题――请教(急啊!!)

我在neatbeans中写的一个注册的的程序,:运行时报以下错误,但是我看了好久都无解,请高手赐教:
下面是浏览器中的报错:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver][SQL Server]第 1 行: ')' 附近有语法错误。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.reg_005frec_jsp._jspService(reg_005frec_jsp.java:253)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


root cause

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]第 1 行: ')' 附近有语法错误。
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
org.apache.jsp.reg_005frec_jsp._jspService(reg_005frec_jsp.java:166)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
以上是报错的信息

下面是我的原代码:

<%@page contentType="text/html"%>
<%@page pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import=" Proj.ISOtoGb2312 "%> ISOtoGb2312是一个字符转化的类
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>收件人信息</title>
</head>
<%
String url ="jdbc:odbc:DB272";

String name = "wangxi"; 这里是我赋的 一个植,下面8个是从表单中得来的
String receivername = ISOtoGb2312.convert(request.getParameter("receivername"));
String sex = ISOtoGb2312.convert(request.getParameter("sex"));
String province = ISOtoGb2312.convert(request.getParameter("province"));
String address = ISOtoGb2312.convert(request.getParameter("address"));
String letter = ISOtoGb2312.convert(request.getParameter("letter"));
String phone = ISOtoGb2312.convert(request.getParameter("phone"));
String sendway = ISOtoGb2312.convert(request.getParameter("sendway"));
String payway = ISOtoGb2312.convert(request.getParameter("payway"));

String sql="";
String column = "";
String values = "";
String insert = "";

if((name!=null)){
column = "name,";
values = "'"+name+"',";

if(receivername!=null){
column += "receivername,";
values += "'"+receivername+"',";
}

if(sex!=null){
column += "sex,";
values += "'"+sex+"',";
}

if(province!=null){
column += "province,";
values += "'"+province+"',";
}

if(address!=null){
column += "address,";
values += "'"+address+"',";
}

if(letter!=null){
column += "letter,";
values += "'"+letter+"',";
}

if(phone!=null){
column += "phone,";
values += "'"+phone+"',";
}

if(sendway!=null){
column += "sendway,";
values += "'"+sendway+"',";
}

if(payway!=null){
column += "payway,";
values += "'"+payway+"',";
}

sql="select * from rec_info where name='"+name+"'";
insert="insert into rec_info ("+column+") values ("+values+")";
System.out.println(insert);
String user = "sa";
String pass = "";
Connection conn=null;
ResultSet rs=null;
int m;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {
out.println("加载驱动器类时出现异常<br>");
}

try {
conn = DriverManager.getConnection(url,user,pass);
}
catch(SQLException e) {
out.println("连接数据库的过程中出现SQL异常<br>");
}

Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs= stmt.executeQuery(sql);

if(rs.next() ){
out.println(rs.getString(2) );
%>
<script language="JavaScript">
alert("用户名已存在,请重新注册");
history.back();
</script>

<% }else {

stmt.executeUpdate(insert);
%>
<script language="JavaScript">
alert("注册成功!");
window.close();
</script>
<%

}}else{

%>
<body>
<center>
<h1>请仔细填写收件人信息:</h1>
</center>
<table width="536" height="389" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000066">
<tr>
<td width="536" height="389"><form name="form1" method="post" action="reg_rec.jsp">
<table width="536" height="321" border="1" cellpadding="0" cellspacing="0" bgcolor="#00FFFF">
<tr>
<td width="99" height="44"> <pre> 收货人姓 名:</pre></td>
<td width="393"><pre>
<input name="receivername" type="text" id="receivername" size="15" maxlength="20"> 性别:<select name="sex" id="sex"><option selected>男</option><option>女</option></select>
</pre></td>
</tr>
<tr>
<td height="36"> <pre> 收货人省/市:</pre></td>
<td> <pre>
<select name="province" id="province"><option selected>请选择</option><option>江西省</option><option>湖南省</option><option>山东省</option><option>北京市</option></select>
</pre></td>
</tr>
<tr>
<td height="42"><pre> 详 细 地 址:</pre></td>
<td><pre>
<input name="address" type="text" id="address" size="30" maxlength="50">
</pre></td>
</tr>
<tr>
<td height="33"><pre> 邮 编:</pre></td>
<td><pre>
<input name="letter" type="text" id="letter" size="10" maxlength="10">
</pre></td>
</tr>
<tr>
<td height="35"><pre> 电 话:</pre></td>
<td><pre>
<input name="phone" type="text" id="phone" size="15" maxlength="15">
</pre></td>
</tr>
<tr>
<td height="44"><pre> 送 货 方 式:</pre></td>
<td><pre>
<select name="sendway" id="sendway"><option selected>国内挂号邮寄</option><option>南昌市五公里内上门送货</option><option>南昌市五公里外上门送货</option><option>不足30元国内特快传递</option><option>30-60元国内特快传递</option><option>60-100元国内特快传递</option><option>100-150元国内特快传递</option><option>150-200元国内特快传递</option><option>200元以上国内特快传递</option></select>
</pre></td>
</tr>
<tr>
<td height="40"><pre> 支 付 方 式:</pre></td>
<td><pre>
<select name="payway" id="payway"><option selected>网上支付</option><option>邮局汇款</option><option>南昌市内上到付款</option><option>建设银行付款</option><option>农业银行付款</option><option>工商银行付款</option><option>招商银行付款</option></select>
</pre></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="提交保存" onclick="return check()">
</p>
</form>
<%}%>
</td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>



</body>
</html>

搜索更多相关主题的帖子: 数据库  浏览器  The  jasper  

----------------解决方案--------------------------------------------------------

if((name!=null)){
column = "name,";
values = "'"+name+"',";少了个括号;


}}else{ ?????没有回括

Connection
Statement
ResultSet
应该放在try{}catch中

最后还没有关闭数据库:

目前只能找到那么多,代码太乱


----------------解决方案--------------------------------------------------------
楼主不应该把数据库连接的代码写到JSP页面里面来
这是非常不好的编程方法
----------------解决方案--------------------------------------------------------

谢谢各位!
我也觉的把数据哭连接的代码放在jsp中是很混乱的 ,
应该将数据库的代码封装起来,是吧?


----------------解决方案--------------------------------------------------------

放到javabean里吧


----------------解决方案--------------------------------------------------------
  相关解决方案