急!jsp调用数据库出错!在线等!(续)
原帖在http://zhidao.baidu.com/question/35972172.html忘记帖程序了<%@pagecontentType="text/html;...
原帖在http://zhidao.baidu.com/question/35972172.html
忘记帖程序了
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" pageEncoding="GBK" import="java.sql.*"%>
<%
Class.forName("com.microsoft.JDBC.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=lj";
String user="sa";
String password="19850708";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String city=request.getParameter("city");
String ci=request.getParameter("ci");
String ljc=request.getParameter("ljc");
int o=Integer.parseInt(ljc);
String sql="insert into biao values("+city+","+ci+","+ljc+")";
String sq="select * from biao where a='"+city+"' and b='"+ci+"' and c="+o+"";
ResultSet rs=stmt.executeQuery(sq);
String sele=" SELECT top 1 * FROM biao WHERE a = '"+city+"' AND b = '"+ci+"' AND c >"+o+"";
if(rs.next())
out.print(rs);
{
String sqq = "IF NOT EXISTS ('"+sq+"') BEGIN '"+sele+"' END";
ResultSet rss = stmt.executeQuery(sqq);
if(rss.next())
{
int rs1=stmt.executeUpdate(sql);
out.print("相近值是" + rss);
}
else
out.print("已经存在。");
}
else
{
out.print("数据库联不上");
}
rs.close();
stmt.close();
conn.close();
%>
大家帮忙看看啊 实在是不知道错哪了
我发现是有全角的空格在 改了就说是else的问题。谢谢你啊。不过我也看不懂这个程序,麻烦帮忙改一下啊。
An error occurred at line: 3 in the jsp file: /deallj.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens
duzhonghua123,谢谢你啊!那要怎么改呢,我是新手,现在还是一片茫然呢。 展开
忘记帖程序了
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" pageEncoding="GBK" import="java.sql.*"%>
<%
Class.forName("com.microsoft.JDBC.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=lj";
String user="sa";
String password="19850708";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String city=request.getParameter("city");
String ci=request.getParameter("ci");
String ljc=request.getParameter("ljc");
int o=Integer.parseInt(ljc);
String sql="insert into biao values("+city+","+ci+","+ljc+")";
String sq="select * from biao where a='"+city+"' and b='"+ci+"' and c="+o+"";
ResultSet rs=stmt.executeQuery(sq);
String sele=" SELECT top 1 * FROM biao WHERE a = '"+city+"' AND b = '"+ci+"' AND c >"+o+"";
if(rs.next())
out.print(rs);
{
String sqq = "IF NOT EXISTS ('"+sq+"') BEGIN '"+sele+"' END";
ResultSet rss = stmt.executeQuery(sqq);
if(rss.next())
{
int rs1=stmt.executeUpdate(sql);
out.print("相近值是" + rss);
}
else
out.print("已经存在。");
}
else
{
out.print("数据库联不上");
}
rs.close();
stmt.close();
conn.close();
%>
大家帮忙看看啊 实在是不知道错哪了
我发现是有全角的空格在 改了就说是else的问题。谢谢你啊。不过我也看不懂这个程序,麻烦帮忙改一下啊。
An error occurred at line: 3 in the jsp file: /deallj.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens
duzhonghua123,谢谢你啊!那要怎么改呢,我是新手,现在还是一片茫然呢。 展开
展开全部
应该是你的if else语句出现了问题!!!我都看不懂,你仔细检查哈你的if-else配对问题!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
{ String sqq = "IF NOT EXISTS ('"+sq+"') BEGIN '"+sele+"' END";
ResultSet rss = stmt.executeQuery(sqq);
你的大括号匹配都乱了,这里多了个大括号,下面的大括号都还有问题 也许你想把这个括号写在if(rs.next()) 后面,if(rs.next()) {
!!!!!
if(rs.next()) {
out.print(rs);
String sqq = "IF NOT EXISTS ('"+sq+"') BEGIN '"+sele+"' END";
ResultSet rss = stmt.executeQuery(sqq);
if(rss.next())
{
int rs1=stmt.executeUpdate(sql);
out.print("相近值是" + rss);
}
else
out.print("已经存在。");
}
else
{
out.print("数据库联不上");
}
ResultSet rss = stmt.executeQuery(sqq);
你的大括号匹配都乱了,这里多了个大括号,下面的大括号都还有问题 也许你想把这个括号写在if(rs.next()) 后面,if(rs.next()) {
!!!!!
if(rs.next()) {
out.print(rs);
String sqq = "IF NOT EXISTS ('"+sq+"') BEGIN '"+sele+"' END";
ResultSet rss = stmt.executeQuery(sqq);
if(rss.next())
{
int rs1=stmt.executeUpdate(sql);
out.print("相近值是" + rss);
}
else
out.print("已经存在。");
}
else
{
out.print("数据库联不上");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询