1. Create a jdbc.properties file
driver=oracle.jdbc.driver.oracledriverurl=jdbc:oracle:thin:@127.0.0.1:1521:orclusername=systempassword=123456
2. Create a connection tool
PackageCom.util;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.SQLException;Importjava.util.Enumeration;ImportJava.util.ResourceBundle; Public classORACLEJDBC {Private StaticString driver; Private StaticString URL; Private StaticString username; Private StaticString password; Static{ResourceBundle Properties= Resourcebundle.getbundle ("Oracle"); Driver= properties.getstring ("Driver"); URL= properties.getstring ("url"); Username= Properties.getstring ("username"); Password= properties.getstring ("Password"); } Public StaticConnection getconnection () {Connection conn=NULL; Try{class.forname (driver); Conn=drivermanager.getconnection (Url,username,password); } Catch(Exception e) {e.printstacktrace (); } returnConn; } Public Static voidCloseConnection (Connection conn) {if(conn!=NULL){ Try{conn.close (); } Catch(SQLException e) {e.printstacktrace (); } } }}
End
Connect to Oracle using JDBC