没有数据引出.为什么? [英] No data extrated. why?

查看:83
本文介绍了没有数据引出.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java& SQL专家,当我运行此jsp页面时,我没有收到提取到表中的任何数据吗?可能是什么原因 ?我收到一种带有四列表的空白页,如下所示.没有从数据库中检索数据,为什么?
我想知道问题是否来自下面的行代码中双冒号的间距.当我消除双冒号之间的空格时,我收到一条错误消息.

Java & SQL experts, when I run this jsp page I don't receive any data extracted into the table? What could be the reason ? I receive sort of a blank page with a four column table as highlighted below. No data is being retrieved from the database, why ?
I'm wondering whether the problem comes from the spacing in the double colons in the line codes below. When I eliminate the space in between the double colons I receive an error message.

<sql : query dataSource="${snapshot}" var="result">
 SELECT * from Employees;
</sql : query>

SELECT * from Employees;
Emp ID年龄名字姓氏

SELECT * from Employees;
Emp ID Age First Name Last Name

这是程序:

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

推荐答案

<%@ 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 id,age,first,last 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>

这篇关于没有数据引出.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆