Java connected to Oracle code

xiaoxiao2021-03-06  69

The latest code to connect Oracle is to match the environment variable:

Classpath = .; E: /J2SDK14/LIB/Tools.jar; E: /oracle/ora90/jdbc/lib/classes12.zip

The test-tested computer has been installed in the Oracle client and can be connected with SQLPLUS. / ** This Sample Shows How To list All the name from the Emp table DRIVER. See The Same Program in the * OCI8 Samples Directory to Seeh How To Use The Other Drivers. * /

// you need to import the java.sql package to use jdbcimport java.sql. *;

class Test {public static void main (String args []) throws SQLException {// Load the Oracle JDBC driver DriverManager.registerDriver (new oracle.jdbc.OracleDriver ()); / * try {Class.forName ( "oracle.jdbc. Driver.Oracledriver ");} catch (exception e) {system.out.println (" no driver! ");} * / // connect to the database name at the @ Sign in the connection URL. // You can use Either the full specified sql * net syntax or a short cut // syntax as : : . The Example Uses The short cut syntax. String Url = "JDBC: Oracle : th: @ 172.28.31.85: 1521: yikatong "; string username =" scott "; string password =" tiger ";

IF (Args.Length> 0) URL = args [0]; if (args.length> 1) username = args [1]; if (args.length> 2) Password = args [2]; system.out.println (URL); System.out.Println (username); system.out.println (password); connection conn = drivermanager.getConnection (URL, Username, Password);

// Create a statement statement stmt = conn.createstatement ();

// select the ename column from the Emp Table resultset Rset = stmt.executequery ("Select * from test");

转载请注明原文地址:https://www.9cbs.com/read-90430.html

New Post(0)