国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java初學者筆記:JDBC連接Oracle數據庫

2019-11-17 04:02:49
字體:
來源:轉載
供稿:網友
view plaincopy to clipboardPRint?
/**  
* JDBCTest.java  
* 編譯腳本  
cd/  
cd D:/JavaHome/temp  
d:  
javac JDBCTest.java  
java  JDBCTest  
pause  
*/  
import java.sql.*;   
// WindowsXP使用JDBC連接Oracle10g數據庫   
// Oracle10g 客戶端安裝在: "D:/OraClient10g"   
public class JDBCTest {   
    public static void main(String args[ ]) {   
        Connection connection = null;   
        Statement statement = null;   
           
        try {   
            // Load the JDBC Driver   
            // 必須在系統環境變量 CLASSPATH 添加 "D:/OraClient10g/jdbc/lib/classes12.zip"   
            String DBDRIVER = "oracle.jdbc.driver.OracleDriver";   
            // 找到 "D:/OraClient10g/NETWORK/ADMIN/tnsnames.ora" 文件, 將 (DESCRIPTION=...)拷貝到下面   
            String URL = "jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = mine)(PORT = 1521)) )(CONNECT_DATA =(SID = cheung)(SERVER = DEDICATED)))";   
            Class.forName(DBDRIVER).newInstance();   
       
            // Connect to the database   
            connection = DriverManager.getConnection(URL, "scott", "tiger");   
            // Obtain a statement object   
            statement = connection.createStatement();   
               
            // Execute the SQL   
            String sql = "select * from JDBC_TEST";   
            ResultSet rs = statement.executeQuery(sql);   
            while (rs.next())   
            {   
                System.out.println(rs.getString(1));  // 列的索引: 1-based   
            }   
            rs.close();   
        }   
        // Don't try this at home, catch SQLException and all others   
        catch( Exception e ) {   
            e.printStackTrace();   
        }   
        finally {   
            // Time to close everthing up.   
            if( statement != null ) {   
                try {   
                    statement.close();   
                }   
                catch( SQLException e ){   
                } // nothing we can do   
            }   
           
            if( connection != null ) {   
                try {   
                    connection.close();   
                }   
                catch( SQLException e ){   
                } // nothing we can do   
            }   
        }   
    }   
}  
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长沙县| 古交市| 祁阳县| 霍城县| 西吉县| 彰武县| 徐汇区| 五原县| 青海省| 贵阳市| 阿勒泰市| 重庆市| 霍山县| 来安县| 高州市| 德令哈市| 兴海县| 鄂托克前旗| 策勒县| 孝昌县| 平南县| 无为县| 江津市| 敦化市| 嵊泗县| 福海县| 通河县| 阳春市| 北宁市| 三台县| 离岛区| 铜陵市| 十堰市| 唐河县| 章丘市| 吉林省| 洛阳市| 伊金霍洛旗| 黄石市| 阆中市| 门源|