1. Import the required jar packages, find ojdbc14.jar and nls_charset12.jar in \ JDBC \ Lib of the Oracle client installation directory, and add these two jar packages to the project.
(A simple method is to create a new directory libs in the project, copy the jar package to the directory, right-click the JAR file, and select Add to build path)
2. Write test code
Import Java. SQL. *; public class main {string dburl = "JDBC: oracle: thin: @ Oracle Database IP: Port Number: database instance name"; string theuser = "mw_sys "; string thepw = "sys"; connection c = NULL; statement conn; resultset rs = NULL; public main () {try {class. forname ("oracle. JDBC. driver. oracledriver "). newinstance (); C = drivermanager. getconnection (dburl, theuser, thepw); Conn = C. createstatement ();} catch (exception e) {e. printstacktrace () ;}} public resultset executequery (string SQL) {rs = NULL; try {rs = conn.exe cutequery (SQL);} catch (sqlexception e) {e. printstacktrace ();} Return Rs;} public void close () {try {Conn. close (); C. close ();} catch (exception e) {e. printstacktrace () ;}} public static void main (string [] ARGs) {resultset RS; main conn = new main (); rs = conn.exe cutequery ("select * from table name"); try {While (RS. next () {system. out. println (RS. getstring ("field name");} catch (exception e) {e. printstacktrace ();}}}
The code above only lists database query operations. Other operations are similar. The red part must be modified.