运行我的JSP页面时,没有从MySQL数据库中提取数据 [英] No data extracted from MySQL database while running my JSP page
问题描述
JSP和sql专家我有一个简短的问题,困扰着我.我是JSP和数据库访问的新手.
我创建了一个mysql数据库,并使用Java程序代码编译通过命令行成功运行了它.
但是,当我尝试使用JSP页面从数据库中提取数据时,我收到的只是一个空的或空白的html表,其中包含四列EMP ID.年龄;名;姓氏.
问题是为什么为什么数据库的html页面中没有显示数据?
我怀疑,根本原因之一可能是产生了错误行消息,但是当我将其格式化为时,我再也没有收到任何错误消息.
请协助.
JSP and sql experts I have a brief problem that is nudging my head. I'm a newbie to JSP and database access.
I created a mysql database and successfully ran it via the command line using Java program code compilation.
However when I try to extract data from the database using JSP page all i receive is an empty or blank html table with four columns of EMP ID; Age; First Name; Last Name.
The problems is why is it that no data is displayed in the html page from the database ?
I'm suspicious one of the root causes may be that produces an error line message, yet when I format it to I don't get any more error messages.
Please assist.
下面是MySQL数据库:
Below is the MySQL database:
database - 'EMP'.
table - 'Employees'.
Columns; id; age; first; last.
data; 100; 28; Zaid; Khan.
password - 'password'
下面是FirstExample.jsp代码.
Below is the FirstExample.jsp code.
<%@ page import="java.io.*, java.util.*, java.sql.*" %>
<%@ page import="javax.servlet.http.*, javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<html>
<head>
<title>SELECT operation</title>
</head>
<body>
<sql : setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/EMP"
user="root" password="password"/>
<sql : query dataSource="${snapshot}" var="result">
SELECT * from Employees;
</sql : query>
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>Age</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.age}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
以下是文件和类路径:
JSP page: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\jsp pages\RegName.jsp
CLASSPATH: C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jstl-1.2.jar;C:\glassfish3\jdk\jre\lib;C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.27-bin.jar
JAVA_HOME: C:\glassfish3\jdk
Path: C:\glassfish3\jdk\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin
推荐答案
<%@ page import="java.io.*, java.util.*, java.sql.*" %>
<%@ page import="javax.servlet.http.*, javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<html>
<head>
<title>SELECT operation</title>
</head>
<body>
<sql : setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/EMP"
user="root" password="password"/>
<sql : query dataSource="${snapshot}" var="result">
SELECT * from Employees;
</sql : query>
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>Age</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.age}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
</tr>`enter code here`
</c:forEach>
</table>
</body>
</html>
这篇关于运行我的JSP页面时,没有从MySQL数据库中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!