| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 681 人关注过本帖
标题:一个数据库问题——请教(急啊!!)
只看楼主 加入收藏
wangxi875230
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-11-16
收藏
 问题点数:0 回复次数:4 
一个数据库问题——请教(急啊!!)

我在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 
2006-11-16 22:18
csaplle001
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-8-26
收藏
得分:0 

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


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

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

最后还没有关闭数据库:

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

2006-11-17 00:47
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
楼主不应该把数据库连接的代码写到JSP页面里面来
这是非常不好的编程方法

可惜不是你,陪我到最后
2006-11-17 10:07
wangxi875230
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-11-16
收藏
得分:0 

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

2006-11-17 11:09
禹_二
Rank: 1
等 级:新手上路
帖 子:661
专家分:0
注 册:2006-9-13
收藏
得分:0 

放到javabean里吧


2006-11-17 13:13
快速回复:一个数据库问题——请教(急啊!!)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033045 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved