千家信息网

Servlet如何操作Oracle

发表于:2025-01-16 作者:千家信息网编辑
千家信息网最后更新 2025年01月16日,这篇文章主要介绍Servlet如何操作Oracle,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!package test;import java.io.IOException;
千家信息网最后更新 2025年01月16日Servlet如何操作Oracle

这篇文章主要介绍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("

");

out.println("

");

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("

");

out.println("

");

out.println("

");

out.println("

");

}

out.println("

Content:
" + rs.getString("ename") + "" + rs.getString("MGR") + "
");

} 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();

}

}

}

}

以上是"Servlet如何操作Oracle"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

0