1、首先建立一個項目:
打開MyEclipse6.0→File→New→Java Project→TestJDBC→進入Oracle10g的安裝目錄(C:\Oracle\product\10.2.0\db_3\jdbc\lib)將ojdbc14.jar包導入新建好的項目。(附:如果用了第三方連接池還要導入classes12.zip)
2、在項目src下面新建一個類OracleTest.Java
輸入以下代碼:
package Oracle.test;
import Java.sql.*;
import Java.util.PropertIEs;
public class Oracletest3
{
/** Oracle數據庫連接URL */
private final static String Oracle_URL = "jdbc:Oracle:thin:@localhost:1521:orcl";
/** Oracle數據庫連接驅動 */
private final static String Oracle_DRIVER = "oracle.jdbc.driver.OracleDriver";
/** 數據庫用戶名 */
private final static String Oracle_USERNAME = "system";
/** 數據庫密碼 */
private final static String Oracle_PASSWord = "shiyue123";
public static void main(String[] args) throws SQLException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn =DriverManager.getConnection (Oracle_URL,
Oracle_USERNAME, Oracle_PASSWord);
tatement stmt=conn.createStatement();
stmt.executeQuery("select * from boy");
System.out.println("success!");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("failer!");
}
}
述:
1521為鏈接端口,orcl為你Oracle的SID(在Oracle裡面查詢SID的語句為select instance_name from v$instance;)