zoukankan      html  css  js  c++  java
  • 数据库连接类:DatabaseConnection

    package com.cjm.dbc;

    import java.sql.*;

    /**
    * @author cjm
    * 使用JDBC 连接 oracle 数据库
    */
    public class DatabaseConnection {

    // 数据库驱动
    public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
    // 连接字符串
    public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:sa";
    // 数据库帐号
    public static final String DBUSER = "cjm";
    // 数据库密码
    public static final String DBPASSWORD = "cjm";
    private Connection conn = null;

    public DatabaseConnection() {
    try {
    // 加载驱动
    Class.forName(DBDRIVER);
    try {
    this.conn = DriverManager.getConnection(DBURL, DBUSER,DBPASSWORD);
    }
    catch (SQLException e) {
    e.printStackTrace();
    }
    }
    catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    }

    //获取数据库链接
    public Connection getConnection() {
    return this.conn;
    }

    // 数据库链接关闭
    public void close() {
    if (this.conn != null) {
    try {
    this.conn.close();
    }
    catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }
    }

  • 相关阅读:
    手工测试
    测试理论
    MySQL常用语法
    Linux设置静态ip
    设计模式
    Shiro
    TreeSet和TreeMap
    UDP和反射
    Linux归纳
    Spring+SpringMVC+Mybatis整合
  • 原文地址:https://www.cnblogs.com/jianming-chan/p/3344652.html
Copyright © 2011-2022 走看看