簡體   English   中英

resultSet中沒有數據-Jsp數據庫

[英]No data in resultSet - Jsp Database

我有這個基本代碼來獲取與oracle數據庫的連接並從名為temp_employee的表中檢索一列。 但是,當我編譯時,它不會在網頁上顯示數據。 它沒有顯示錯誤消息。 只是一個空白頁。 您能否幫助使此代碼正常工作?

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import ="java.sql.*" %>
<%@ page import=" javax.sql.DataSource" %>
<html>
<head>

    <title>Database</title>
</head>
<body>
        <%
            Connection connection = null;
            try {
                // Load the JDBC driver
                String driverName = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driverName);

                connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:dev", "root", "root");

                Statement statement = connection.createStatement(); 

                ResultSet resultSet = statement.executeQuery("SELECT aadName from temp_employee");    
                while (resultSet.next()) { 

                    String code = resultSet.getString("aadName");

                }; 

            } catch (ClassNotFoundException e) {

                 out.println("Driver caused Exception : " + e.getMessage() + "");

                // Could not find the database driver
            } catch (SQLException e) {
                // Could not connect to the database
                 out.println("Database caused Exception : " + e.getMessage() + "");
            }

        %>          


</body>

</html>

在您的html主體中進行一些更改,在Connection聲明之后,聲明String code = null; 並將現有代碼更改為code = resultSet.getString("aadName"); 然后在html正文中添加以下行, <h2><%= code %></h2>

實際上,腳本表達式用於將代碼值插入輸出流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM