"This article describes"
The previous several said so much, finally did not talk about how to connect to the database with Java, this article is practical, talk about how to connect the database.
"Java Connection to Oracle database"
1 . Import the JDBC driver: see here, busy looking for the driver on the Internet? No, the installation of Oracle has its own driver, the path is: The installation directory \product\11.2.0\dbhome_1\jdbc\lib, below a number of jar packages, choose the one that suits you (the simplest way is to import the project to see if you can connect, Can be connected is the appropriate driver)
2. Code:
about the URL: @ After the IP: port, these two do not know how to check the blog: http://www.cnblogs.com/xiaoMzjm/p/3884470.html
about SQL statements : You see inside the table name in the "" enclosed, the thing is, I use the graphical tool navicat for Oracle to build the table, to access the table to add "", the command line to build the table is not used. this deserves attention! "User" and user are two different tables!
1 Packagecom.zjm.www.test;2 3 Importjava.sql.Connection;4 ImportJava.sql.DriverManager;5 ImportJava.sql.ResultSet;6 Importjava.sql.Statement;7 8 Public classTest {9 Ten Public Static voidgetDate () { OneString driverclass= "Oracle.jdbc.driver.OracleDriver"; AString url= "Jdbc:oracle:thin: @localhost: 1521:orcl"; -String username= "Test"; -String password= "Aaa38324836"; theString sql= "select * from \" Myuser\ ""; - Try{ -Class.forName (Driverclass). newinstance ();//Load Driver -Connection conn=drivermanager.getconnection (Url,username,password);//Get Connected +Statement stmt=conn.createstatement (); -ResultSet rs=stmt.executequery (SQL); + while(Rs.next ()) { ASystem.out.println (rs.getstring ("name")); at } -}Catch(Exception e) { - E.printstacktrace (); - } - } - in /*** Main function*/ - Public Static voidMain (string[] args) { to getDate (); + } -}