为了账号安全,请及时绑定邮箱和手机立即绑定

大神看看哪里错了

大神看看哪里错了

三年不见丶 2017-08-08 16:38:45
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"  import="java.sql.*"%><!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=UTF-8"><title>Insert title here</title></head><body> <% int number; String bookname; int price; Connection con=null; Statement st=null; ResultSet rs=null; String driverClass="com.mysql.jdbc.Driver"; String url="jdbc:mysql://localhost/js1?useUnicode=true&characterEncoding=utf8"; String username="root"; String password="123456"; try{ Class.forName(driverClass); con=DriverManager.getConnection(url,username,password); st=con.createStatement(); String sql="select * from table1"; rs=st.executeQuery(sql); if(rs!=null){ out.print("<table width=300 border=1 cellspacing=0>"); out.print("<tr><td>书名</td><td>单价</td>"); out.print("<td>库存量</td></tr>"); while(rs.next()){ bookname=rs.getString("name"); price=rs.getInt("price"); number=rs.getInt("number"); out.print("tr><td>"+bookname+"</td><td>"+price+"</td>"); out.print("<td>"+number+"</td></tr>"); } out.print("</table>"); } }catch(Exception e){ out.print("发生数据库异常"); e.printStackTrace(System.err); } %></body></html>
查看完整描述

目前暂无任何回答

  • 0 回答
  • 1 关注
  • 1500 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信