Get the App
SLTechnology News&Howtos  ›  Development  › 

How Servlet operates Oracle

Shulou Source: shulou.com Published: 2022-06-02 13:34:38 09月18日 Update

This article mainly introduces Servlet how to operate Oracle, the article is very detailed, has a certain reference value, interested friends must read it!

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 ("Content:")

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 ("" + rs.getString ("ename") + "")

Out.println ("" + rs.getString ("MGR") + "")

Out.println ("")

}

Out.println ("")

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

}

}

}

}

The above is all the contents of the article "how Servlet operates Oracle". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Content articles value interests guys partners more knowledge industry information channels channels references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Docker Huawei vpn