用JavaBean實現資料庫的串連和關閉,在jsp頁面輸出資料庫中student表中學生的資訊

來源:互聯網
上載者:User

標籤:

package com.hanqi.test;import java.sql.*;public class XveSheng {     Connection conn;     Statement st;     ResultSet rs;         public Connection getConn() {        return conn;    }    public void setConn(Connection conn) {        this.conn = conn;    }    public Statement getSt() {        return st;    }    public void setSt(Statement st) {        this.st = st;    }    public ResultSet getRs() {        return rs;    }    public void setRs(ResultSet rs) {        this.rs = rs;    }    public void lianjie()    {                       try        {                    Class.forName("oracle.jdbc.driver.OracleDriver");            String strUrl = "jdbc:oracle:thin:@localhost:1521:orcl"    ;            conn  = DriverManager.getConnection(strUrl, "test", "5211314");                    System.out.println("串連資料庫成功!");        }        catch (Exception e)        {                        e.printStackTrace();                    }             }    public void guanbi()    {        try         {            conn.close();            st.close();            rs.close();        }         catch (SQLException e)        {            e.printStackTrace();        }                    }    }
<%@page import="com.hanqi.test.XveSheng"%><%@page import="java.sql.*"%><%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>學生資訊</title></head><body><div align="center"><font size="20px">學生資訊表</font></div><table border="1" cellspacing="0" width="80%" align="center" style="text-align: center"><tr><td height="40">學號</td><td >姓名</td><td >性別</td><td >生日</td><td>班級</td></tr><%     XveSheng xs = new XveSheng();     xs.lianjie();     xs.setSt(xs.getConn().createStatement());     xs.setRs(xs.getSt().executeQuery("select * from student"));     while(xs.getRs().next())        {                      String sno = xs.getRs().getString(1);                     String sname = xs.getRs().getString(2);           String ssex = xs.getRs().getString(3);           Date sbirthday= xs.getRs().getDate(4);           String sclass = xs.getRs().getString(5);                 %> <tr><td height="40"><%=sno %></td><td ><%=sname %></td><td ><%=ssex %></td><td ><%=sbirthday.toString() %></td><td><%=sclass %></td></tr> <%        }     xs.guanbi();%></table></body></html>

用JavaBean實現資料庫的串連和關閉,在jsp頁面輸出資料庫中student表中學生的資訊

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.