<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'h6mysql.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </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="root";
%>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
%>
<%
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBUSER,DBUSER,DBPASS);
String sql="SELECT empno,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{
rs.close();
pstmt.close();
conn.close();
}
%>
</body>
</html>
我找了一个读取mysQL数据库数据的例子(代码上) 编译没有错误 打开tomcat后想在网页中打开,就会弹出“错误1”,再看网页就是正在加载……,数据库建立如“错误2” 请问高人这是怎么回事啊??应该怎样修改呢??麻烦了!!!希望高手不吝赐教!!!数据库mysqljspstringstylesheet
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'h6mysql.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </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="root";
%>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
%>
<%
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBUSER,DBUSER,DBPASS);
String sql="SELECT empno,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{
rs.close();
pstmt.close();
conn.close();
}
%>
</body>
</html>
我找了一个读取mysQL数据库数据的例子(代码上) 编译没有错误 打开tomcat后想在网页中打开,就会弹出“错误1”,再看网页就是正在加载……,数据库建立如“错误2” 请问高人这是怎么回事啊??应该怎样修改呢??麻烦了!!!希望高手不吝赐教!!!数据库mysqljspstringstylesheet
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql="SELECT empno,ename,job,sal,hiredate FROM emp";
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);