zoukankan      html  css  js  c++  java
  • 常用数据库的连接方式

    --------------------------Mysql数据库----------------------------
    url=jdbc:mysql://127.0.0.1:3306/数据库名称
    user=root//用户名
    password=123456 //密码                                                                                                                                      

    ---------------------------Oracle数据库---------------------------                                                                                                                                                                                                                                                                                    String URL = "jdbc:oracle:thin:@localhost:1521:ORCL";
    String USERNAME = "system";//用户名
    String PWD = "RZKruizhukai123";//密码

    -------------------------QLServer2000数据库 --------------------

    String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=数据库名字";
    String user="sa"; //用户名
    String password="";//密码
     
    ---------------------------------可以把上面的装在配置文件中  方便读取-------------------

    public Connection getConnection() throws Exception{
    //1.创建配置文件并得到对象输入流
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("db.properties");
    //2.创建propetities
    Properties pro= new Properties();
    pro.load(is);
    //3. 通过key-value 的方式得到相对应的值
    String driver = pro.getProperty("driver");
    String url = pro.getProperty("url");
    String user = pro.getProperty("user");
    String password = jdbc.getProperty("password");
    //4.加载运行时类对象
    Class.forName(driver);
    //5通过DriverManager得到连接
    Connection connection = DriverManager.getConnection(url,user,password);
    return connection;
    }

     
     
     
  • 相关阅读:
    11. Container With Most Water
    9. Palindrome Number
    375. 猜数字大小 II leetcode java
    leetcode 72 编辑距离 JAVA
    73. 矩阵置零 leetcode JAVA
    快速排序 JAVA实现
    63. 不同路径 II leetcode JAVA
    重写(override)与重载(overload)
    62 不同路径 leetcode JAVA
    leetcode 56 合并区间 JAVA
  • 原文地址:https://www.cnblogs.com/rzkwz/p/12405637.html
Copyright © 2011-2022 走看看