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

    MySQL:
     String Driver="com.mysql.jdbc.Driver"; //驱动程序
     String URL="jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name为数据库名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).new Instance();
     Connection con=DriverManager.getConnection(URL,Username,Password);
     Microsoft SQL Server:
     1)
     String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接SQL数据库的方法
     String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).new Instance(); //加载数据可驱动
     Connection con=DriverManager.getConnection(URL,UserName,Password); //
     2)
     String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //连接SQL数据库的方法
     String URL="jdbc:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).new Instance(); //加载数据可驱动
     Connection con=DriverManager.getConnection(URL,UserName,Password);
     Sysbase:
     String Driver="com.sybase.jdbc.SybDriver"; //驱动程序
     String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name为tb数据可名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).newInstance();
     Connection con=DriverManager.getConnection(URL,Username,Password);
     Oracle(用thin模式):
     String Driver="oracle.jdbc.driver.OracleDriver"; //连接数据库的方法
     String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl为数据库的SID
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).newInstance(); //加载数据库驱动
     Connection con=DriverManager.getConnection(URL,Username,Password);
     PostgreSQL:
     String Driver="org.postgresql.Driver"; //连接数据库的方法
     String URL="jdbc:postgresql://localhost/db_name"; //db_name为数据可名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).newInstance();
     Connection con=DriverManager.getConnection(URL,Username,Password);
     String Driver="org.postgresql.Driver"; //连接数据库的方法
     DB2:
     String Driver="com.ibm.db2.jdbc.app.DB2.Driver"; //连接具有DB2客户端的Provider实例
     //String Driver="com.ibm.db2.jdbc.net.DB2.Driver"; //连接不具有DB2客户端的Provider实例
     String URL="jdbc:db2://localhost:50000/db_name"; //db_name为数据可名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).newInstance();
     Connection con=DriverManager.getConnection(URL,Username,Password);
     Informix:
     String Driver="com.informix.jdbc.IfxDriver";
     String URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver"; //db_name为数据可名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).newInstance();
     Connection con=DriverManager.getConnection(URL,Username,Password);
     JDBC-ODBC:
     String Driver="sun.jdbc.odbc.JdbcOdbcDriver";
     String URL="jdbc:odbc:dbsource"; //dbsource为数据源名
     String Username="username"; //用户名
     String Password="password"; //密码
     Class.forName(Driver).newInstance();
     Connection con=DriverManager.getConnection(URL,Username,Password);

  • 相关阅读:
    Java高级之类结构的认识
    14.8.9 Clustered and Secondary Indexes
    14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器
    14.8.3 Physical Row Structure of InnoDB Tables InnoDB 表的物理行结构
    14.8.2 Role of the .frm File for InnoDB Tables InnoDB 表得到 .frm文件的作用
    14.8.1 Creating InnoDB Tables 创建InnoDB 表
    14.7.4 InnoDB File-Per-Table Tablespaces
    14.7.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量和大小
    14.7.1 Resizing the InnoDB System Tablespace InnoDB 系统表空间大小
    14.6.11 Configuring Optimizer Statistics for InnoDB 配置优化统计信息用于InnoDB
  • 原文地址:https://www.cnblogs.com/spinsoft/p/2570999.html
Copyright © 2011-2022 走看看