Servlet連線Oracle
把oracle的驅動$ORACL_HOME/jdbc/lib/ojdbc6.jar拷貝到D:\Tomcat5.5.17\webapps\my\WEB-INF\lib。(因為執行時需要該jar包)
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-2638122/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle(+)連線與Join連線Oracle
- Oracle左連線,右連線Oracle
- ORACLE 半連線與反連線Oracle
- Oracle的左連線和右連線Oracle
- PHP 連線 OraclePHPOracle
- PHP 連線oraclePHPOracle
- jdbc連線oracleJDBCOracle
- sqlserver連線oracleSQLServerOracle
- mysql 連線oracleMySqlOracle
- navicat 連線 oracleOracle
- Oracle 表連線Oracle
- SQLSERVER 連線 ORACLESQLServerOracle
- ruby連線OracleOracle
- oracle外連線Oracle
- ORACLE 連線方式Oracle
- Oracle連線方式Oracle
- QTP連線OracleQTOracle
- thinkphp連線OraclePHPOracle
- cx_Oracle 連線 OracleOracle
- Oracle內連線、外連線、右外連線、全外連線小總結Oracle
- Oracle 表連線方式詳解(外連結、內連線、自連線)Oracle
- 【SQL】Oracle的內連線、左外連線、右外連線及全外連線SQLOracle
- oracle 連線查詢Oracle
- DBA ORACLE連線操作Oracle
- ORACLE 表連線方式Oracle
- jdbc 連線 oracle racJDBCOracle
- Python連線oraclePythonOracle
- Oracle 連線池配置Oracle
- oracle中字串連線Oracle字串
- oracle bbed的連線Oracle
- oracle表連線方式Oracle
- oracle occi 連線池Oracle
- oracle中的連線Oracle
- 連線oracle報錯Oracle
- 【Oracle】--連線查詢Oracle
- oracle 會話,連線Oracle會話
- Servlet操作OracleServletOracle
- Oracle的表連線方法(三)雜湊連線Oracle