Connect to oracle, with general addition, deletion, modification, and query methods

Source: Internet
Author: User

Connect to oracle, with general addition, deletion, modification, and query methods

package cn.jbit.pet.dao;import java.sql.*;public class BaseDao {protected Connection conn=null;protected PreparedStatement pstmt=null;protected ResultSet rs=null;public void getConnection() {try {Class.forName("oracle.jdbc.driver.OracleDriver");} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}        try {conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","ok");} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void closeAll() {try {if(rs!=null){rs.close();}if(pstmt!=null){pstmt.close();}if(conn!=null){conn.close();}} catch (SQLException e) {e.printStackTrace();}}        public int executeUpdateSQL(String sql,Object []param){     int num=0;     try {     getConnection();pstmt=conn.prepareStatement(sql);if(param!=null){for (int i = 0; i < param.length; i++) {pstmt.setObject(i+1, param[i]);}}num=pstmt.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{closeAll();}return num;    }    public void executeQuerySQL(String sql,Object []param){     try {     getConnection();pstmt=conn.prepareStatement(sql);if(param!=null){for (int i = 0; i < param.length; i++) {pstmt.setObject(i+1, param[i]);}}rs=pstmt.executeQuery();} catch (SQLException e) {e.printStackTrace();}    } }

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.