Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Servlet operates Oracle

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report