打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
连接各种数据库方式速查表
 各个开发商的接口并不完全相同,所以开发环境的变化会带来一定的配置变化。主要集合了不同数据库的连接方式。
  连接各种数据库方式速查表
  下面罗列了各种数据库使用JDBC连接的方式,可以作为一个手册使用。
  1、Oracle8/8i/9i数据库(thin模式)
  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
  Stringurl="jdbcracle:thinlocalhost:1521rcl";//orcl为数据库的SID
  Stringuser="test";
  Stringpassword="test";
  Connectionconn=DriverManager.getConnection(url,user,password);
  2、DB2数据库
  Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
  Stringurl="jdbc:db2://localhost:5000/sample";//sample为你的数据库名
  Stringuser="admin";
  Stringpassword="";
  Connectionconn=DriverManager.getConnection(url,user,password);
  3、SqlServer7.0/2000数据库
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
  Stringurl="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
  //mydb为数据库
  Stringuser="sa";
  Stringpassword="";
  Connectionconn=DriverManager.getConnection(url,user,password);
  4、Sybase数据库
  Class.forName("com.sybase.jdbc.SybDriver").newInstance();
  Stringurl="jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名
  PropertiessysProps=System.getProperties();
  SysProps.put("user","userid");
  SysProps.put("password","user_password");
  Connectionconn=DriverManager.getConnection(url,SysProps);
  5、Informix数据库
  Class.forName("com.informix.jdbc.IfxDriver").newInstance();
  Stringurl="jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
  user=testuser;password=testpassword";//myDB为数据库名
  Connectionconn=DriverManager.getConnection(url);
  6、MySQL数据库
  Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  Stringurl="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
  //myDB为数据库名
  Connectionconn=DriverManager.getConnection(url);
  7、PostgreSQL数据库
  Class.forName("org.postgresql.Driver").newInstance();
  Stringurl="jdbc:postgresql://localhost/myDB"//myDB为数据库名
  Stringuser="myuser";
  Stringpassword="mypassword";
  Connectionconn=DriverManager.getConnection(url,user,password);
  8、access数据库直连用ODBC的
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Stringurl="jdbcdbcriver={MicroSoftAccessDriver(*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
  Connectionconn=DriverManager.getConnection(url,"","");
  StatementstmtNew=conn.createStatement();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JDBC连接各种数据库经验技巧集萃
JDBC连接数据库过程
jdbc连接数据库
JAVA如何连接数据库
JDBC介绍
请教JDBC怎么连接ORACLE数据库
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服