zoukankan      html  css  js  c++  java
  • Java程序连接各种数据库的driver和url形式

    1.Oracle数据库

    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    String url = "jdbc:oracle:thin:@localhost:1521:orcle";
    String user = "test";
    String password = "test";
    Connection conn = DriverManager.getConnection(url, user, password);
    

     2.DB2数据库

    Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
    String url = "jdbc:db2://localhost:5000/testDB";
    String user = "admin";
    String password = "test";
    Connection conn = DriverManager.getConnection(url, user, password);
    

     3.SQL Server数据库

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB";
    String user = "sa";
    String password = "test";
    Connection conn = DriverManager.getConnection(url, user, password);

    4. Sybase数据库

    Class.forName("com.sybase.jdbc.SybDriver").newInstance();
    String url = "jdbc:sybase:Tds:localhost:5007/testDB";
    Properties sysProps = System.getProperties();
    sysProps.put("user", "userid");
    sysProps.put("password", "user_password");
    Connection conn = DriverManager.getConnection(url, sysProps);
    

     5.Informix数据库

    Class.forName("com.infoxmix.jdbc.IfxDriver").newInstance();
    String url = "jdbc:infoxmix-sqli://localhost:1533/testDB:INFORMIXSERVER=myserver;user=testuser;password=testpassword";
    Connection conn = DriverManager.getConnection(url);
    

     6.MySQL数据库

    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    String url = "jdbc:mysql://localhost/testDB?user=testuser&password=testpassword&useUnicode=true&characterEncoding=GB2312";
    Connection conn = DriverManager.getConnection(url);
    

     7.PostgreSQL数据库

    Class.forName("org.postgresql.Driver").newInstance();
    String url = "jdbc:postgresql://localhost/testDB";
    String user = "myuser";
    String password = "test";
    Connection conn = DriverManager.getConnection(url, user, password);
    
    每日积累一点,都是进步的见证。
  • 相关阅读:
    为什么要把MySQL的binlog格式修改为row
    面试官:你知道大事务会带来什么问题以及如何解决么?
    TCP三次握手、四次挥手、滑动窗口、流量控制
    SpringCloud Gateway拦截器遇到的小坑汇总
    Zipkin客户端链路追踪源码解析
    Hystrix失败处理逻辑解析
    Feign自动装配原理
    SpringCloud服务调用源码解析汇总
    Zipkin架构简介
    C#+Selenium抓取百度搜索结果前100网址
  • 原文地址:https://www.cnblogs.com/smart-hwt/p/8136448.html
Copyright © 2011-2022 走看看