Servlet操作Oracle
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
public class Conndb extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
out.println("<table border=1>");
out.println("<tr><td>Content:</td></tr>");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.250:1521:test", "scott", "tiger");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from emp");
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString("ename") + "</td>");
out.println("<td>" + rs.getString("MGR") + "</td>");
out.println("</tr>");
}
out.println("</table>");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt= null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22990797/viewspace-2638121/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Servlet連線OracleServletOracle
- Oracle 集合操作Oracle
- oracle基本操作Oracle
- 使用“純”Servlet做一個單表的CRUD操作Servlet
- DBA ORACLE連線操作Oracle
- Servlet系列:(一)servlet原理剖析Servlet
- Servlet 規範和 Servlet 容器Servlet
- oracle dg切換操作示例Oracle
- ORACLE透明加密安裝操作Oracle加密
- 96.Servlet Servlet生命週期Servlet
- JSP實現servlet對資料庫的增刪查改操作JSServlet資料庫
- Servlet第二篇【Servlet呼叫圖、Servlet細節、ServletConfig、ServletContext】ServletContext
- Oracle Dataguard故障轉移(failover)操作OracleAI
- Oracle 重置密碼及基本操作Oracle密碼
- oracle truncate table recover(oracle 如何拯救誤操作truncate的表)Oracle
- JavaWeb——ServletJavaWebServlet
- Servlet概述Servlet
- JavaWEB - ServletJavaWebServlet
- java操作Oracle 方式一 ( 連線-》操作-》斷開連線 )JavaOracle
- Oracle OCP(11):操作大資料集Oracle大資料
- Oracle生成awr報告操作步驟Oracle
- truncate操作消除ORACLE SEG壞塊解析Oracle
- Servlet 新手教程Servlet
- Servlet-HelloWorldServlet
- Servlet筆記Servlet筆記
- Servlet_6Servlet
- Servlet 規範Servlet
- 初學ServletServlet
- Servlet入門Servlet
- Java之ServletJavaServlet
- Servlet 如何工作Servlet
- Oracle實驗6--掌握Oracle資料庫的日誌操作Oracle資料庫
- Servlet3.0新特性-非同步處理Servlet、FilterServlet非同步Filter
- C#連線和操作Oracle資料C#Oracle
- Oracle資料庫日期格式轉換操作Oracle資料庫
- Oracle dos連線資料庫基本操作Oracle資料庫
- oracle全文索引之commit與DML操作Oracle索引MIT
- Oracle 檢視可以DML操作的條件Oracle