Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the way Java connects to various databases?

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how Java connects to various databases". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the way Java connects to various databases"?

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 (); 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); at this point, I believe you have a deeper understanding of "how Java connects to various databases". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report