XML scriptlet 串連資料庫

來源:互聯網
上載者:User

標籤:cti   man   htm   ati   串連   username   ora   cep   串連數   

 1 <%@ page language="java" contentType="text/html" pageEncoding="GBK" %> 2 <%@ page import="java.sql.*" %> 3  4 <html> 5     <head> 6         <title>emp列表</title> 7          8          9     </head>10     <body>11         <%!12             public static final String DBDRIVER="oracle.jdbc.driver.OracleDriver";13             public static final String DBURL="jdbc:oracle:thin:@localhost:1521:orcl";14             public static final String DBUSERNAME="scott";15             public static final String DBPASSWORD="orcl";16         %>17         <%18             Connection conn = null;19             PreparedStatement ps = null;20             ResultSet rs = null;21             try{22                 Class.forName(DBDRIVER);23                 conn = DriverManager.getConnection(DBURL,DBUSERNAME,DBPASSWORD);24                 String sql="select empno,ename,job,sal,hiredate from emp";25                 ps = conn.prepareStatement(sql);26                 rs = ps.executeQuery();27                 28         %>29                 <table border="1" width="80%">30                     <tr bgcolor="red">31                         <td>員工編號</td>32                         <td>員工姓名</td>33                         <td>員工職位</td>34                         <td>員工薪資</td>35                         <td>入職日期</td>36                     </tr>37                 <%38                     while(rs.next()){39                         int empno=rs.getInt(1);40                         String ename=rs.getString(2);41                         String job=rs.getString(3);42                         int sal=rs.getInt(4);43                         java.util.Date hiredate=rs.getDate(5);44                 %>        45                     <tr bgcolor="gray">46                         <td> <%=empno %> </td>47                         <td> <%=ename %> </td>48                         <td> <%=job %> </td>49                         <td> <%=sal %> </td>50                         <td> <%=hiredate %> </td>51                     </tr>52                     <%53                     }54                     %>    55                 </table>56                 57         <%    58             }catch(Exception e){59                 //拋異常60                 System.out.println(e);61             }finally{62                 if(rs!=null){63                     rs.close();64                 }65                 if(ps!=null){66                     ps.close();67                 }68                 if(conn!=null){69                     conn.close();70                 }    71             }72         %>73             74     </body>75 </html>

 

XML scriptlet 串連資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.