##########
# Access #
##########
package ch02;
import java.sql.*;
public class ConnAccess {
public static void main(String[] args) {
try {
String url = "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=F:/Program/XS.mdb";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from S_DM_TCXX");
while (rs.next()) {
System.out.println(rs.getString("TCMC"));
}
conn.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
###########
# 1.MySQL #
###########
Class.forName( " org.gjt.mm.mysql.Driver " );
Connection conn = DriverManager.getConnection( " jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName " , sUsr, sPwd );
#########################
# 2.Microsoft SQLServer #
#########################
Class.forName( " com.microsoft.jdbc.sqlserver.SQLServerDriver " );
Connection conn = DriverManager.getConnection( " jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master " , sUsr, sPwd );
############
# 3.Oracle #
############
Class.forName( " oracle.jdbc.driver.OracleDriver " );
Connection conn = DriverManager.getConnection( " jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL " , sUsr, sPwd );
#########
# 4.DB2 #
#########
Class.forName( " com.ibm.db2.jdbc.net.DB2Driver " );
String url = " jdbc:db2://192.9.200.108:6789/SAMPLE "
Connection conn = DriverManager.getConnection( url, sUsr, sPwd );
##########
# 5.ODBC #
##########
Class.forName( " sun.jdbc.odbc.JdbcOdbcDriver " );
Connection conn = DriverManager.getConnection( " jdbc:odbc: " + sDsn, sUsr, sPwd );
################
# 6.PostgreSQL #
################
Class.forName( " org.postgresql.Driver " );
Connection conn = DriverManager.getConnection( " jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName " , sUsr, sPwd );
阅读(894) | 评论(0) | 转发(0) |