2 li1227401051 li1227401051 于 2016.04.01 13:01 提问

jsp连接mysql时运行sql语句失败

四月 01, 2016 12:51:30 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [/Test] threw exception [An exception occurred processing JSP page /register.jsp at line 49

46:
47: Connection conn = DriverManager.getConnection(url);
48: Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
49: ResultSet rs = stmt.executeQuery(sql);
50:
51: out.print("房间号");
52: out.print("|");

Stacktrace:] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '???' at line 1
at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1370)
at org.apache.jsp.register_jsp._jspService(register_jsp.java:132)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

2个回答

li1227401051
li1227401051   2016.04.01 13:04

这里是简单代码段 比较low 刚接触,谢谢各位:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" import="java.sql.Statement" import="java.sql.*" %>



用户注册表


<%
try{
Class.forName("com.mysql.jdbc.Driver");
out.println("加载Mysql Driver成功!
");
}
catch(Exception e)
{
out.println("加载Mysql Driver失败!
");
e.printStackTrace();
}
%>
String sql="select * from 房间表";
String url = "jdbc:mysql://localhost/Hotel?user=root&password=136334&useUnicode=true&characterEncoding=8859_1&useSSL=false";

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

out.print("房间号");
out.print("|");
out.print("状态");
out.print("|");
out.print("价格");
out.print("
");

while(rs.next()){
out.print(rs.getString("房间号")+" ");
out.print("|");
out.print(rs.getString("状态")+" ");
out.print("|");
out.print(rs.getString("价格"));
out.print("
");
}
out.print("
");

rs.close();
stmt.close();
conn.close();
%>

zhouyufengqingyang
zhouyufengqingyang   2016.04.01 13:25

String url = "jdbc:mysql://localhost/Hotel?user=root&password=136334&useUnicode=true&characterEncoding=8859_1为什么没有端口号?

li1227401051
li1227401051 已经解决了,数据库名改成英文就行了。。。。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
jsp+mysql连接数据库基本操作,增删改查,样样齐全。含有sql语句!
连接数据库基本操作,增删改查,样样齐全。含有sql语句 适合初学者。
用STS写JSP页面连接数据库时出现500错误的解决办法
在写jsp页面时,出现了500错误,连接数据库失败,是jdk没有解析JDBC jar包的原因,将JDBC的Jar包拷贝到java jdk文件夹下的jre/lib/ext文件夹下即可解决。
jsp sql 查询中文时无效,英文正常
连接数据库使用下列格式的字符串: jdbc:mysql://127.0.0.1:3306/dbname?useUnicode=true&characterEncoding=UTF-8&user=test&password=111 dbname为数据库, test为用户名, 111为密码, characterEncoding=UTF-8 为其编码 其中characte
mysql执行sql语句偶尔出错, 找出了罪魁祸首
update t_word set yesterday_num = 46648, yesterday_order = 3, increase= today_num - 46648, on_board = 1 + on_board  where time=2008-02-27 and word = xx" 碰到更新的字段中又包含自己的时候,mysql 4.xx 执行偶尔出现错误。例如上面
JSP网站系统数据库Mysql封装及连接主要代码
<br />package DB;<br />import java.sql.*;<br />public class DBManager {<br /> Connection conn = null;<br /> Statement stmt = null;<br /> ResultSet rs = null;<br /> String DB = "连接数据库名"; // 数据库名<br /> String Password = "输入数据库密码"; // 数据库登陆密码<br /> String use
JSP中多条SQL语句同时执行
con.setAutoCommit(true);//设为true,每次executeUpdate将立刻被执行 sql = "insert into table1(lable1) values(001)"; rs = stmt.executeUpdate(sql); sql = "insert into table2(lable2) values(002
在jsp中使用JDBC连接mysql数据库出现错误
在jsp中连接mysql数据库时产生的java.lang.ClassNotFoundException: com.mysql.jdbc.Driver问题        这个问题又浪费了我一晚上的时间,不过值得了,终于还是让我连上了mysql数据库。并通过tomcat服务器查询到了数据库里的文件信息。所以可以往后面继续前进了,值得了。         Class.forName("com.m
mysql无法执行某些语句,并自动断开服务连接问题
错误提示: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet su
jsp连接MySQL实现插入insert操作
请尊重作者劳动成果,转载时但请务必标明出处!!本人保留追究法律责任的权利。谢谢合作! 下午终于实现了jsp连接MySQL执行插入操作的功能。在index.jsp页面输入数据,提交到mysql——insert.jsp页面进行插入数据库的操作。 index.jsp页面代码如下: [html] view plaincopy %@
kettle学习之连接数据库资源库执行sql时报错
使用kettle6.1版本做数据清洗时,新建数据库资源库时执行sql语句出错,连接资源库失败