首页 > 编程知识 正文

jdbc连接数据库的代码,java代码怎么连接数据库

时间:2023-05-05 05:05:32 阅读:151386 作者:148

1、Oracle8/8i/9i数据库(精简模式) class.forname (' Oracle.JDBC.driver.Oracle driver ' ).newInstance ); string URL=' JDBC : Oracle : thin : @ localhost 33601521: orcl '; //orcl是数据库的SID String user='test '; String password='test '; connection conn=driver manager.getconnection (URL,user,password );

2、DB2数据库class.forname (com.IBM.DB2.JDBC.app.DB2 driver ).newInstance ); string URL=' JDBC : db 2://localhost 33605000/sample '; //sample是您的数据库名称String user='admin '; 字符串密码=' '; connection conn=driver manager.getconnection (URL,user,password );

3、Sql Server7.0/2000数据库class.forname (com.Microsoft.JDBC.SQL server.SQL server driver ) ).newInstance; string URL=' JDBC : Microsoft : SQL server ://localhost 33601433; DatabaseName=mydb '; //mydb是数据库字符串用户=' sa '; 字符串密码=' '; connection conn=driver manager.getconnection (URL,user,password );

4、Sybase数据库class.forname (com.Sybase.JDBC.syb driver ).newInstance ); string URL=' JDBC : Sybase : TDS : localhost 33605007/mydb '; //myDB是您的数据库名称properties sysprops=system.get properties (; sysprops.put(user ),userid ); sysprops.put(password,) user_password; connection conn=driver manager.getconnection (URL,SysProps );

5、Informix数据库class.forname (' com.Informix.JDBC.ifx驱动程序' ).newInstance ); string URL=' JDBC : Informix-sqli ://123.45.67.8933601533/mydb : Informix server=my server; 用户=testuser; password=testpassword '; //myDB是数据库名称connection conn=driver manager.getconnection (URL );

6、MySQL数据库class.forname (org.gjt.mm.MySQL.driver ) ).newInstance ); string URL=' JDBC : MySQL ://localhost/mydb? user=soft password=soft 1234 use unicode=true优秀可乐=8859_1'/mydb是数据库名称connection conn=driver manager.getconnectiod

7、PostgreSQL数据库class.forname (org.PostgreSQL.driver ) ).newInstance; string URL=' JDBC : PostgreSQL ://localhost/mydb '/mydb是数据库名称String user='myuser '; string password='我的密码'; connection conn=driver manager.getconnection (URL,user,password );

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。