Tomcat 5.0 MySQL 4.1 ,在JSP页面中用JDBC(mysql…
2008-02-23 09:33:57来源:互联网 阅读 ()
try { Connection con; Statement stmt; ResultSet rs; //加载驱动程序,下面的代码为加载MySQL驱动程序 Class.forName("com.mysql.JDBC.Driver"); //注册MySQL驱动程序 DriverManager.reGISterDriver(new com.mysql.jdbc.Driver()); //用适当的驱动程序连接到数据库 String dbUrl = "jdbc:mysql://localhost:3306/BookDB?useUnicode=true&characterEncoding=GB2312"; String dbUser="dbuser"; String dbPwd="1234"; //建立数据库连接 con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd); //创建一个JDBC声明 stmt = con.createStatement(); //增加新记录 stmt.executeUpdate("INSERT INTO books (id,name,title,price) VALUES ('999','Tom','Tomcat Bible',44.5)"); //查询记录 rs = stmt.executeQuery("SELECT id,name,title,price from books"); //输出查询结果 out.println(""); while (rs.next()) { String col1 = rs.getString(1); String col2 = rs.getString(2); String col3 = rs.getString(3); float col4 = rs.getFloat(4); //convert character encoding col1=new String(col1.getBytes("ISO-8859-1"),"GB2312"); col2=new String(col2.getBytes("ISO-8859-1"),"GB2312"); col3=new String(col3.getBytes("ISO-8859-1"),"GB2312"); //打印所显示的数据 out.println("" col1 "" col2 "" col3 "" col4 ""); } out.println(""); //删除新增加的记录 stmt.executeUpdate("DELETE FROM books WHERE id='999'"); //关闭数据库连结 rs.close(); stmt.close(); con.close(); } //捕获错误信息 catch (Exception e) {out.println(e.getMessage());}
错误如下: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream ** BEGIN NESTED EXCEPTION ** java.io.IOException MESSAGE: Unexpected end of input stream STACKTRACE: java.io.IOException: Unexpected end of input stream at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1096) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:626) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562) at com.mysql.jdbc.Connection.(Connection.java:491) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346) at java.sql.DriverManager.getConnection(DriverManager.java:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at org.apache.jsp.DbJsp_jsp._jspService(DbJsp_jsp.java:75) at org.apache.jASPer.runtime.HttpJsPBase.service(HttpJspBase.java:94) at javax.Servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:595) ** END NESTED EXCEPTION ** 请问可能是哪里出了问题?上一篇: 快速排序方法Java实现与分析。
下一篇: 我的java学习经验谈3
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 百度地图api在Html中显示,在jsp页面中不显示解决方法 2018-06-18
- 使用技巧:在JSP页面中的应用JavaBean 2008-02-23
- 在JSP页面中轻松实现数据饼图 2008-02-23
- 不建议在jsp页面中直接写语句连接数据库 2008-02-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash