Java操作Oracle数据库以及调用存储过程

操作Oracle数据库

publicclass DBConnection {

    //jdbc:oracle:thin:@localhost:1521:orcl

    publicstaticfinal String url = "jdbc:oracle:thin:@localhost:1521:ORCL";

    publicstatic Connection conn ;

   

    static{

        //获取数据库驱动

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

    }

   

    publicstatic Connection getConn(){

        try {

               //连接数据库

            conn = DriverManager.getConnection(url, "scott", "tiger");

        } catch (SQLException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        return  conn;

    }

   

   

    publicstaticvoid closeConn(Connection conn){

        try {

               //关闭数据库

            if(conn != null && !conn.isClosed()){

                conn.close();

            }

        } catch (SQLException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

    }

   //测试

    publicstaticvoid main(String[] args) {

        System.out.println(getConn() != null);

    }

调用存储过程

Java操作Oracle数据库以及调用存储过程

上一篇:JavaSE基础知识(5)—面向对象(5.4面向对象三大特征:封装、继承、多态)


下一篇:MyPanel与QWidget使用QStyle设置背景色的不同