JSP 串連Oracle資料庫例子

來源:互聯網
上載者:User

<%
  Class.forName("Oracle.jdbc.driver.OracleDriver");   //.newInstance();
  String url="jdbc:oracle:thin:@127.0.0.1:1521:yyyy";
   //mydb為資料庫的SID,10.0.1.1 為 資料庫伺服器 IP
  String user="sys as sysdba";
  String password="yyyy";
  Connection conn= DriverManager.getConnection(url, user, password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";  //test 是表名,要先建立這個表,再送幾條記錄
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next())
  {
%>
    第一個欄位內容為:<%=rs.getString(1)%>
    第二個欄位內容為:<%=rs.getString(2)%> <br>
<%
  }
  out.print("資料庫操作成功,恭喜。");

  rs.close();
  stmt.close();
  conn.close();
%>

相關文章

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.