Chinaunix首页 | 论坛 | 博客
  • 博客访问: 542717
  • 博文数量: 128
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 1345
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-22 21:43
文章分类

全部博文(128)

文章存档

2009年(30)

2008年(98)

我的朋友

分类: Java

2008-07-01 21:15:09

##########
# 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) |
给主人留下些什么吧!~~