a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 93|回复: 0

[综合] 调用JDBC驱动的方法

[复制链接]
发表于 2012-8-4 13:54:49 | 显示全部楼层 |阅读模式
Oracle、MySQL、SQL Server 2000调用JDBC驱动的方法是本文我们主要要介绍的内容,接下来我们就来一一介绍这部分内容。     1、连接Oracle数据库, r2 F; r8 K3 s" Z
    Class.forName("oracle.jdbc.driver.OracleDriver");) \( s, O7 B. w$ f- O
    Connection con =DriverManager.getConnection("jdbc:oracle:thin:@host:port:dbname", user, password);
- i' d6 C  x- u% E5 ~    if(con!=null)+ A# b/ i3 f0 L' L* H
    System.out.println("test success");0 o. E  H+ h8 B
    }catch(Exception e){  e.printStackTrace();+ f  y  S2 Z6 [: R  @8 I
    端口一般默认是1521
" x: P) z8 m" a8 s( x! Y7 d    2、连接MySQL数据库/ [5 O9 ~3 M5 N/ e4 K; B5 C( q
    Class.forName("com.mysql.jdbc.Driver");6 L* r' m- y  u& j  w. t
    Connection con =DriverManager.getConnection("jdbc:mysql://host:port/dbname", user, password);
5 P0 k5 W* U0 ]& f    if(con!=null)
  _3 D6 O/ |  q' p/ ^9 P0 T5 o    System.out.println("test success");
; S  `: Z- G# T9 P! x; Z    }catch(Exception e){  e.printStackTrace();# P3 Y, [1 M7 P& y
    端口一般默认是3306。4 o% n$ v8 H1 G& G6 a3 X1 {6 p7 M. f
    3、连接SQL Server 2000数据库* I0 u* o% B6 s
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
0 D9 u- G5 {3 d' G    Connection con =DriverManager.getConnection("jdbc:microsoft:sqlserver://host:port;databaseName=dbname;# u& c. |& h/ i1 q
    ", user, password);//注意url后面有个引号' {0 ?, J* j2 D( A  m% U; L& l9 X  |
    if(con!=null)www.ExamW.CoM
* g3 k3 M9 T* i3 c9 P, m    System.out.println("test success");9 T" U* n6 {$ M, O) z0 X2 B
    }catch(Exception e){  e.printStackTrace();
& v$ v" x7 ~+ `- D    端口一般默认是1433。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-6-18 23:27 , Processed in 0.238415 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表