代码如下:
<%@ page contentType=”text/html” pageEncoding=”GBK”%>
<%@ page import=”java.sql.*”%>
<html>
<head>
<title>www.mldnjava.cn;高端Java培训</title>
</head>
<body>
<%!
public static final String DBDRIVER =”org.gjt.mm.mysql.Driver” ;
public static final String DBURL =”jdbc:mysql://localhost:3306/mldn” ;
public static final String DBUSER = “root” ;
public static final String DBPASS =”mysqladmin” ;
%>
<%
Connection conn = null;
PreparedStatement pstmt =null;
ResultSet rs = null;
%>
<%
try{
Class.forName(DBDRIVER);conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql = “select emp.ename,job,sal,hiredate FROM emp”;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
%>
<center>
<table border = “1” width = “80%”>
<tr>
<td>雇员编号</td>
<td>雇员姓名</td>
<td>雇员工作</td>
<td>雇员工资</td>
<td>雇佣日期</td>
</tr>
<%
while(rs.next()){
int empno = rs.getInt(1);
String ename = rs.getString(2);
String job = rs.getString(3);
float sal = rs.getFloat(4);
java.util.Date date = rs.getDate(5);
%>
<tr>
<td><%=empno%></td>
<td><%=ename%></td>
<td><%=job%></td>
<td><%=sal%></td>
<td><%=date%></td>
</tr>
<%
}
%>
</table>
</center>
<%
}catch(Exception e){
System.out.println(e);
}finally{
if(rs !=null)
rs.close();
if(pstmt !=null)
pstmt.close();
if(conn !=null)
conn.close();
}
%>
</body>
</html>
在tomcat中显示:java.sql.SQLException:Access denied for user “”root”” @””localhost”” <using password:yes>
本人是新手,有担心可能是本人数据库没连接上,希望能耐心帮本人解决,先谢谢了。
<%@ page contentType=”text/html” pageEncoding=”GBK”%>
<%@ page import=”java.sql.*”%>
<html>
<head>
<title>www.mldnjava.cn;高端Java培训</title>
</head>
<body>
<%!
public static final String DBDRIVER =”org.gjt.mm.mysql.Driver” ;
public static final String DBURL =”jdbc:mysql://localhost:3306/mldn” ;
public static final String DBUSER = “root” ;
public static final String DBPASS =”mysqladmin” ;
%>
<%
Connection conn = null;
PreparedStatement pstmt =null;
ResultSet rs = null;
%>
<%
try{
Class.forName(DBDRIVER);conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql = “select emp.ename,job,sal,hiredate FROM emp”;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
%>
<center>
<table border = “1” width = “80%”>
<tr>
<td>雇员编号</td>
<td>雇员姓名</td>
<td>雇员工作</td>
<td>雇员工资</td>
<td>雇佣日期</td>
</tr>
<%
while(rs.next()){
int empno = rs.getInt(1);
String ename = rs.getString(2);
String job = rs.getString(3);
float sal = rs.getFloat(4);
java.util.Date date = rs.getDate(5);
%>
<tr>
<td><%=empno%></td>
<td><%=ename%></td>
<td><%=job%></td>
<td><%=sal%></td>
<td><%=date%></td>
</tr>
<%
}
%>
</table>
</center>
<%
}catch(Exception e){
System.out.println(e);
}finally{
if(rs !=null)
rs.close();
if(pstmt !=null)
pstmt.close();
if(conn !=null)
conn.close();
}
%>
</body>
</html>
在tomcat中显示:java.sql.SQLException:Access denied for user “”root”” @””localhost”” <using password:yes>
本人是新手,有担心可能是本人数据库没连接上,希望能耐心帮本人解决,先谢谢了。