In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
What are the common ways to connect to JDBC databases? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. JDBC connects to DB2
Class.forName ("Com.ibm.db2.jdbc.net.DB2Driver"); String url= "jdbc:db2://dburl:port/DBname" cn = DriverManager.getConnection (url, sUsr, sPwd)
2. JDBC connects to Microsoft SQLServer (microsoft)
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver"); cn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://DBServerIP:1433;databaseName=master", sUsr, sPwd)
3. JDBC connects to Sybase (jconn2.jar)
Class.forName ("com.sybase.jdbc2.jdbc.SybDriver"); cn = DriverManager.getConnection ("jdbc:sybase:Tds:DBServerIP:2638", sUsr, sPwd)
4. JDBC connects to MySQL (mm.mysql-3.0.2-bin.jar)
Class.forName ("org.gjt.mm.mysql.Driver"); cn = DriverManager.getConnection ("jdbc:mysql://DBServerIP:3306/myDatabaseName", sUsr, sPwd)
5. JDBC connection PostgreSQL (pgjdbc2.jar)
Class.forName ("org.postgresql.Driver"); cn = DriverManager.getConnection ("jdbc:postgresql://DBServerIP/myDatabaseName", sUsr, sPwd)
6. JDBC connects to Oracle (classes12.jar)
Class.forName ("oracle.jdbc.driver.OracleDriver"); cn = DriverManager.getConnection ("jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd)
7. JDBC connects to ODBC
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn = DriverManager.getConnection ("jdbc:odbc:" + sDsn, sUsr, sPwd)
The jdbc connection method for some databases is not fixed, depending on the driver package you use.
For example, mssql's jtdsjar package:
Database URL:jdbc:jtds:sqlserver://localhost:1433;DatabaseName=XXX
Driver class: net.sourceforge.jtds.jdbc.Driver
1. Oracle8/8i/9i database (thin mode)
Class.forName ("oracle.jdbc.driver.OracleDriver") .newInstance (); String url= "jdbc:oracle:thin:@localhost:1521:orcl"; / / orcl is the SID String user= "test" of the database; String password= "test"; Connection conn= DriverManager.getConnection (url,user,password)
2. DB2 database
Class.forName ("com.ibm.db2.jdbc.app.DB2Driver"). NewInstance (); String url= "jdbc:db2://localhost:5000/sample"; / / sample is your database name String user= "admin"; String password= ""; Connection conn= DriverManager.getConnection (url,user,password)
3. Sql Server7.0/2000 database
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver") .newInstance (); String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; / / mydb is the database String user= "sa"; String password= ""; Connection conn= DriverManager.getConnection (url,user,password)
4. Sybase database
Class.forName ("com.sybase.jdbc.SybDriver"). NewInstance (); String url = "jdbc:sybase:Tds:localhost:5007/myDB"; / / myDB is your database name Properties sysProps = System.getProperties (); SysProps.put ("user", "userid"); SysProps.put ("password", "user_password"); Connection conn= DriverManager.getConnection (url, SysProps)
5. Informix database
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 is the database name Connection conn= DriverManager.getConnection (url)
6. MySQL database
Class.forName ("org.gjt.mm.mysql.Driver") .newInstance (); / or Class.forName ("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" / / myDB is the database name Connection conn= DriverManager.getConnection (url)
7. PostgreSQL database
Class.forName ("org.postgresql.Driver") .newInstance (); String url = "jdbc:postgresql://localhost/myDB" / / myDB is the database name String user= "myuser"; String password= "mypassword"; Connection conn= DriverManager.getConnection (url,user,password)
8. ODBC is directly connected to access database.
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, ","). After reading the above, have you mastered any common ways to connect JDBC databases? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.