大神看看哪里错了

<%@ 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>


三年不见丶
浏览 1501回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP