jsp连接mysql总是出错,求大神帮我
我已经装了jdbc驱动了,也建好了数据库simple和表book原代码:<%@pagelanguage="java"import="java.util.*"pageEnc...
我已经装了jdbc驱动了,也建好了数据库simple和表book
原代码:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>
<title>JSP读取数据库</title> </head> <body>
<table border="1" align="center"> <tr>
<th>书号</th> <th>书名</th> <th>作者</th> <th>出版社</th> </tr>
<%
String driverClass="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/simple";//之前数据库名simple String user="root";//MySQ帐号 String password="root";//MYSQL密码 Connection conn;
try {
Class.forName(driverClass).newInstance();
conn=DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(); String sql="SELECT * FROM book";//表名book ResultSet rs=stmt.executeQuery(sql); while(rs.next()){ %>
<tr>
<td><%=rs.getString("bookid")%></td> <td><%=rs.getString("bookname")%></td> <td><%=rs.getString("writer")%></td> <td><%=rs.getString("publish")%></td> </tr> <%
}
}catch(Exception ex){ ex.printStackTrace(); } %> </body> </html> 展开
原代码:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>
<title>JSP读取数据库</title> </head> <body>
<table border="1" align="center"> <tr>
<th>书号</th> <th>书名</th> <th>作者</th> <th>出版社</th> </tr>
<%
String driverClass="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/simple";//之前数据库名simple String user="root";//MySQ帐号 String password="root";//MYSQL密码 Connection conn;
try {
Class.forName(driverClass).newInstance();
conn=DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(); String sql="SELECT * FROM book";//表名book ResultSet rs=stmt.executeQuery(sql); while(rs.next()){ %>
<tr>
<td><%=rs.getString("bookid")%></td> <td><%=rs.getString("bookname")%></td> <td><%=rs.getString("writer")%></td> <td><%=rs.getString("publish")%></td> </tr> <%
}
}catch(Exception ex){ ex.printStackTrace(); } %> </body> </html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询