In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Package com.xian.jdbc
Import java.sql.Connection
Import java.sql.DriverManager
Import java.sql.PreparedStatement
Import java.sql.ResultSet
Import java.sql.SQLException
Import javax.servlet.jsp.jstl.sql.Result
Import javax.servlet.jsp.jstl.sql.ResultSupport
Public class OracleConnection {
/ * *
* connect to ora database
* @ return con
* @ throws ClassNotFoundException
* @ throws SQLException
* @ author Jia Xiaoxian
, /
Public static Connection getOracleConnection () throws ClassNotFoundException,SQLException {
String driver= "oracle.jdbc.driver.OracleDriver"
String url= "jdbc:oracle:thin:@127.0.0.1:1521:orcl"
Class.forName (driver)
Connection con=DriverManager.getConnection (url, "scott", "7758521")
Return con
}
/ * *
* close the ora connection channel
* @ return
* @ throws SQLException
* @ author Jia Xiaoxian
, /
Public void freeResources (ResultSet resultSet,PreparedStatement pStatement,Connection con) throws SQLException {
If (resultSet.isClosed () = = false)
ResultSet.close ()
If (pStatement.isClosed () = = false)
PStatement.close ()
If (con.isClosed () = = false)
Con.close ()
}
/ * *
* query Sql with no parameters
* @ return Result
* @ throws Exception
* @ author Jia Xiaoxian
, /
Public Result runSelectSql (String sql) {
Connection con=null
PreparedStatement pStatement=null
ResultSet resultSet=null
Result result=null
Try {
Con=getOracleConnection ()
PStatement=con.prepareStatement (sql)
ResultSet=pStatement.executeQuery ()
Result=ResultSupport.toResult (resultSet)
} catch (Exception e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
} finally {
Try {
FreeResources (resultSet, pStatement, con)
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
}
Return result
}
/ * *
* query Sql with parameters
* @ return Result
* @ throws Exception
* @ author Jia Xiaoxian
, /
Public Result runSelectSql (String sql,Object [] params) {
Connection con=null
PreparedStatement pStatement=null
Result result=null
ResultSet resultSet=null
Try {
Con=getOracleConnection ()
PStatement=con.prepareStatement (sql)
For (int iTuno Bandi)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.