数据库使用JDBC连接的方式
下面罗列了各种数据库使用JDBC连接的方式,可以作为一个手册使用。
1、Oracle8/8i/9i/10g/11g数据库(thin模式)
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
2、DB2数据库
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
3、Sql Server7.0/2000数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
4、Sql Server 2005/2008数据库
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
5、Sybase数据库
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
6、Informix数据库
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword"; //myDB为数据库名
Connection conn= DriverManager.getConnection(url);
7、MySQL数据库
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//myDB为数据库名
Connection conn= DriverManager.getConnection(url);
8、PostgreSQL数据库
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
9、access数据库直连用ODBC的
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,"","");
Statement stmtNew=conn.createStatement() ;
数据库使用JDBC连接的方式的更多相关文章
- 各种数据库使用JDBC连接的方式
Java数据库连接(JDBC)由一组用 Java 编程语言编写的类和接口组成.JDBC 为工具/数据库开发人员提供了一个标准的 API,使他们能够用纯Java API 来编写数据库应用程序.然而各个开 ...
- JDBC 连接Oracle 数据库,JDBC 连接Mysql 数据库
首先是JDBC 连接Oracle 数据库 package com.util; import com.pojo.UserInfo; import java.sql.*; public class DB ...
- Oracle可插拔数据库的jdbc连接串写法
我在服务器上部署某个第三方系统的数据库的时候,服务器数据库版本为oracle 12c.我采用的方式是新建了一个实例.访问正常. 后来项目的负责人告诉我,oracle12C支持所谓的可插拔数据库.可插拔 ...
- 转!!各种数据库的jdbc驱动下载及连接方式
各种数据库驱动 数据库名称 下载地址 说明 Mysql http://www.mysql.com/products/connector/j/ Shipped. But need to download ...
- JDBC 连接
转载至:https://www.liyongzhen.com/ 在这一小节,我们将学习DriverManager对象和connection对象. DriverManager对象用于从驱动里获取一个co ...
- oracle 12c jdbc连接pdb报错的问题
有同学发来消息说,oracle数据库使用jdbc连接会后报ora-12505错误. 下意识地回复说查看jdbc连接串中的数据库sid/服务名是否写错了. 对方反馈说没错.然后让他以下面的方式连接是可以 ...
- spring实例化dataSource使用jndi和jdbc两种方式
一.使用jndi的方式 这种方式方便测试人员不需要改代码,直接改变tomcat的server.xml就可以更改数据库连接 spring创建bean <bean id="dataSour ...
- android连接Mysql数据库之JDBC方式
一.创建一个数据库和若干表,并导入相关信息.这里以我之前使用的一个图书系统的数据库为例子. 首先假设已经安装并配置好Mysql.(建议大家安装WAMP,也就是安装完这个,就相当于安装了Mysql,PH ...
- jdbc连接MySQL数据库+简单实例(普通JDBC方法实现和连接池方式实现)
jdbc连接数据库 总结内容 1. 基本概念 jdbc的概念 2. 数据库连接 数据库的连接 DAO层思想 重构设计 3. 事务 概念 事务的ACID属性 事务的操作 4. 连接池 为什么要使用连接池 ...
随机推荐
- JFreeChart应用实例-折线图
http://www.tuicool.com/articles/Nr2Yna JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt. ...
- gstreamer——文档/资源/使用
http://gstreamer.freedesktop.org/src/ http://gstreamer.freedesktop.org/data/doc/gstreamer/head/qt-gs ...
- python中类(class)和实例(instance)
面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...
- 简要总结ajax工作原理及优缺点
虽然在实际的项目中使用多种ajax请求,但就其工作原理,优缺点尚未深入总结, 参考:http://www.cnblogs.com/SanMaoSpace/archive/2013/06/15/3137 ...
- 基于Visual c++ 2012的php扩展开发 - HelloWord!
1.cmd进入命令行模式,并进入php-5.6.20-src/ext源代码的ext目录下输入命令php ext_skel_win32.php --extname=HelloWord,执行结果如下图: ...
- leetcode刷题1:两数之和two_sum
题目:(难度:Easy) 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, ...
- RHCE学习笔记 管理1 (第三~五章)
第三章 红帽企业linux 获取帮助 (略) man .pinfo. 第四章 编辑文件 1.输出重定向到文件和程序 >file 定向文件(覆盖) >>file 定向文件(附 ...
- eclipse异常关了,tomcat如何关
eclipse异常关了,tomcat如何关 ? 1.bin文件夹下面有的shutdown.bat.双击即可! 2.在任务管理器里面关闭,看到javaw.exe关闭也行.
- 【bzoj2815】灾难[ZJOI2012](拓扑排序+lca)
题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2815 原版题解:http://fanhq666.blog.163.com/blog/st ...
- LeetCode——Construct Binary Tree from Preorder and Inorder Traversal
Question Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may as ...