• 常见数据库连接方式


    记下来以留着以后忘记了查看

    MySQL:

    1      String Driver="com.mysql.jdbc.Driver";    //驱动程序  
    2      String URL="jdbc:mysql://localhost:3306/db_name";    //连接的URL,db_name为数据库名      
    3      String Username="username";    //用户名  
    4      String Password="password";    //密码  
    5      Class.forName(Driver);  
    6      Connection con=DriverManager.getConnection(URL,Username,Password);  

    Oracle:

    1      String Driver="oracle.jdbc.driver.OracleDriver";    //连接数据库的方法  
    2      String URL="jdbc:oracle:thin:@loaclhost:1521:orcl";    //orcl为数据库的SID  
    3      String Username="username";    //用户名  
    4      String Password="password";    //密码  
    5      Class.forName(Driver) ;    //加载数据库驱动  
    6      Connection con=DriverManager.getConnection(URL,Username,Password);     

     PostgreSQL:  

    1  String Driver="org.postgresql.Driver";    //连接数据库的方法  
    2      String URL="jdbc:postgresql://localhost/db_name";    //db_name为数据库名  
    3      String Username="username";    //用户名  
    4      String Password="password";    //密码  
    5      Class.forName(Driver) ;      
    6      Connection con=DriverManager.getConnection(URL,Username,Password);  

     DB2:  

    1      String Driver="com.ibm.dbjdbc.app.DBDriver";    //连接具有DB2客户端的Provider实例  
    2      //String Driver="com.ibm.dbjdbc.net.DBDriver";    //连接不具有DB2客户端的Provider实例  
    3      String URL="jdbc:db2://localhost:5000/db_name";    //db_name为数据库名  
    4      String Username="username";    //用户名  
    5      String Password="password";    //密码  
    6      Class.forName(Driver) ; 

     Microsoft SQL Server :   

    1   String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";    //连接SQL数据库的方法  
    2      String URL="jdbc:sqlserver://localhost:1433;DatabaseName=db_name";    //db_name为数据库名  
    3      String Username="username";    //用户名  
    4      String Password="password";    //密码  
    5      Class.forName(Driver).new Instance();    //加载数据可驱动  
  • 相关阅读:
    Ocelot(一)- .Net Core开源网关
    Extensions for Vue
    Vue Study [2]: Vue Router
    Vue Study [1]: Vue Setup
    获取当月的第一天和最后一天示例
    常规正则验证表达式
    当需要向数据库插入空值时,sql语句的判断
    让 IE支持圆角的方法
    服务器上传图片案例
    validatebox相关验证
  • 原文地址:https://www.cnblogs.com/xujingyang/p/6628255.html
Copyright © 2020-2023  润新知