熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

常用數據庫 JDBC 連接寫法全攻略

2022-06-13   來源: Oracle 

  常用數據庫JDBC連接寫法
  
   MySQL()mmmysqlbinjar
  ClassforName( orggjtmmmysqlDriver );
  cn = DriverManagergetConnection( jdbc:mysql://MyDbComputerNameOrIP:/myDatabaseName sUsr sPwd );
   
   PostgreSQL()pgjdbcjar
  ClassforName( orgpostgresqlDriver );
  cn = DriverManagergetConnection( jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName sUsr sPwd );
   
   Oracle()classeszip
  ClassforName( oraclejdbcdriverOracleDriver );
  cn = DriverManagergetConnection( jdbcracle:thin:@MyDbComputerNameOrIP::ORCL sUsr sPwd );
   
   Sybase()jconnjar
  ClassforName( comsybasejdbcjdbcSybDriver );
  cn = DriverManagergetConnection( jdbc:sybase:Tds:MyDbComputerNameOrIP: sUsr sPwd );
  //(DefaultUsername/Password: dba/sql)
   
   Microsoft SQLServer()
  ClassforName( netsourceforgejtdsjdbcDriver );
  cn = DriverManagergetConnection( jdbc:jtds:sqlserver://MyDbComputerNameOrIP:/master sUsr sPwd );
   
   Microsoft SQLServer()
  ClassforName( commicrosoftjdbcsqlserverSQLServerDriver );
  cn = DriverManagergetConnection( jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:;databaseName=master sUsr sPwd );
   
   ODBC
  ClassforName( sunjdbcodbcJdbcOdbcDriver );
  Connection cn = DriverManagergetConnection( jdbcdbc: + sDsn sUsr sPwd );
   
  DB
  ClassforName(DBDriver);
  String url=jdbc:db://:/SAMPLE
  cn = DriverManagergetConnection( url sUsr sPwd );
From:http://tw.wingwit.com/Article/program/Oracle/201311/17201.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.