java和连接数据库的驱动_java中连接各数据库的驱动类和连接方式

1.JAVA连接ACCESS数据库

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");

Connection conn = DriverManager.getConnection(url,"","");

在上面的连接方法中,所涉及到的参数含义如下所示:

* sun.jdbc.odbc.JdbcOdbcDriver:驱动程序类的名称。

* /Data/ReportDemo.mdb:数据库文件

* 其中的用户名和密码均为空

2.JAVA连接MySQL数据库

Class.forName("org.gjt.mm.mysql.Driver");

String url="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&userUnicode=true&characterEncoding=8859_1"

Connection conn = DriverManager.getConnection(url);

在上面的连接方法中,所涉及到的参数含义如下所示:

* org.gjt.mm.mysql.Driver:驱动程序类的名称

* localhost:数据库的地址

* myDB:数据库的名称

* soft:访问数据库的用户名

* soft1234:访问数据库的密码

* 8859_1:使用的字符集。

3.JAVA连接SQL Server 7.0/2000数据库

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";

String user="sa";

String password="";

Connection conn = DriverManager.getConnection(url,user,password);

在上面的连接方法中,所涉及到的参数含义如下所示:

* com.microsoft.jdbc.sqlserver.SQLServerDriver:驱动程序类的名称

* localhost:数据库的地址

* 1433:数据库服务的端口

* myDB:数据库的名称

* user:访问数据库的用户名

* password:访问数据库的密码

4.JAVA连接Oracle 8/8i/9i数据库(thin模式)

Class.forName("oracle.jdbc.driver.OracleDriver");

String url="jdbc:oracle:thin:@192.168.0.1:1521:orcl";

String user="test";

String password="test";

Connection conn = DriverManager.getConnection(url,user,password);

在上面的连接方法中,所涉及到的参数含义如下所示:

* oracle.jdbc.driver.OracleDriver:驱动程序类的名称

* jdbc:oracle:thin:使用thin模式连接

* 192.168.0.1:数据库的IP地址

* 1521:数据库服务的端口,这是Oracle的默认值

* orcl:数据库的SID

* user:访问数据库的用户名

* password:访问数据库的密码

5.JAVA连接DB2数据库

Class.forName("com.ibm.db2.jdbc.app.DB2Driver");

String url="jdbc:db2://127.0.0.1:5000/sample";

String user="admin";

String password="";

Connection conn = DriverManager.getConnection(url,user,password);

在上面的连接方法中,所涉及到的参数含义如下所示:

* com.ibm.db2.jdbc.app.DB2Driver:驱动程序类的名称

* 127.0.0.1:数据库的IP地址

* 5000:数据库服务的端口

* sample:数据库的名称

* user:访问数据库的用户名

* password:访问数据库的密码

6.JAVA连接Sybase数据库

Class.forName("com.sybase.jdbc.Sybdriver");

String url="jdbc:sybase:Tds:localhost:5007/myDB";

Properties sysProps = System.getProperties();

SysProps.put("user","userid");

SysProps.put("password","user_password");

Connection conn = DriverManager.getConnection(url,SysProps);

在上面的连接方法中,所涉及到的参数含义如下所示:

* com.sybase.jdbc.Sybdriver:驱动程序类的名称

* localhost:数据库的地址

* 5007:数据库服务的端口

* myDB:数据库的名称

* userid:访问数据库的用户名

* user_password:访问数据库的密码

7.JAVA连接Informix数据库

Class.forName("com.informix.jdbc.IfxDriver");

String url="jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;user=testuser;password=testpassword";

Connection conn = DriverManager.getConnection(url);

在上面的连接方法中,所涉及到的参数含义如下所示:

* com.informix.jdbc.IfxDriver:驱动程序类的名称

* 123.45.67.89:数据库的地址

* 1533:数据库服务的端口

* myDB:数据库的名称

* myserver:数据库服务器的名称

* testuser:访问数据库的用户名

* testpassword:访问数据库的密码

8.JAVA连接PostgreSQL数据库

Class.forName("org.postgresql.Driver");

String url="jdbc:postgresql://localhost/myDB";

String user="myuser";

String password="mypassword";

Connection conn = DriverManager.getConnection(url,user,password);

在上面的连接方法中,所涉及到的参数含义如下所示:

* org.postgresql.Driver:驱动程序类的名称

* localhost:数据库的地址

* myDB:数据库的名称

* myserver:数据库服务器的名称

* myuser:访问数据库的用户名

* mypassword:访问数据库的密码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
最近刚好有个项目要连接ACCESS的MDB数据并导入到ORACLE,使用 Java代码 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String strurl="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=E:\\\\db.mdb"; Connection conn=DriverManager.getConnection(strurl); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String strurl="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=E:\\\\db.mdb"; Connection conn=DriverManager.getConnection(strurl); 时报了以下的错误 java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序,苦与网上基本上找不到原因只能上外文网找找了 经过GOOGLE后找到一个jstels连接方式http://www.csv-jdbc.com/ 这个网有比较强大的连接csv\xml\dbf\mdb\engine的驱动,需要的同学可以上这个网上下载 这里提供mdb的连接驱动和使用说明 Installation Add the driver jar files (mdbdriver.jar + required third-party libraries) to your classpath or extract these jars to the directory of your application. Driver Classes Description Classes Driver class (JDBC API v1.0) jstels.jdbc.mdb.MDBDriver2 Data Source class (JDBC API v2.0) jstels.jdbc.mdb.MDBDataSource2 Connection Pool Data Source class (JDBC API v2.0) jstels.jdbc.mdb.MDBConnectionPoolDataSource2 URL Syntax The connection URL is jdbc:jstels:mdb:path_to_mdb_file, where path_to_mdb_fileis: an absolute or relative path to a Microsoft Access database (MDB or ACCDB) file, e.g.: jdbc:jstels:mdb:c:/mdb_directory/test.mdb jdbc:jstels:mdb:mdb_directory/test2.mdb jdbc:jstels:mdb:mdb_directory/access2007.accdb path to a file within the CLASSPATH (read-only), e.g.: jdbc:jstels:mdb:classpath://resources/test.mdb path to a file within a ZIP (JAR) file (read-only), e.g.: jdbc:jstels:mdb:zip://c:/dir/archive.zip/test.mdb path to a file located on a FTP server (syntax: ftp://user:password@hostname[:port]/[dirpath/]mdbfile), e.g.: jdbc:jstels:mdb:ftp://login:password@somesite.com:21/mdb_directory/test.mdb SFTP URL to the SFTP-server directory (syntax: sftp://user:password@hostname[:port]/[dirpath/]mdbfile, also required third-party libraries Commons VFS and JSch for this protocol), e.g.: jdbc:jstels:mdb:sftp://login:password@somesite.com:22/mdb_directory/test.mdb HTTP URL to a file (read-only), e.g.: jdbc:jstels:mdb:http://www.somesite.com/mdb_directory/test.mdb SMB/CIFS URL to a file located on a SMB/CIFS server (e.g.: MS Windows share or Samba server, syntax: smb://[user:password@]hostname/share/[dirpath/]mdbfile): jdbc:jstels:mdb:smb://your_server/your_share/mdb_directory/test.mdb jdbc:jstels:mdb:smb://login:password@your_server/your_share/mdb_directory/test.mdb

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值