jdbc+oracle測試類別。

來源:互聯網
上載者:User

標籤:.sql   pass   ora   print   引入   final   cti   body   ace   

package org.portal.service;

 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* 測試連接oracle資料庫
* @author wpc
*
*/

public class Test {
//驅動,URL,使用者名稱,密碼
private static final String driver = "oracle.jdbc.driver.OracleDriver";
private static final String url = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String username = "zjuser";
private static final String password = "zjpass";

public static Connection getConnection() {
Connection connection = null;
try {
// 加 載驅動
Class.forName(driver);
// 通過驅動管理類擷取資料庫連接
connection = DriverManager.getConnection(url, username, password);
// 關閉串連
//connection.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}

// 測試oracle串連是否成功
public static void main(String[] args) throws SQLException {
Connection connection = Test.getConnection();
if (connection != null) {
System.out.println("串連oracle資料庫成功:" + connection);
//這裡具體查詢資料庫中的資料,可以直接取出。
/* String sql = "select * FROM BUSER";
Statement st = connection.createStatement();
st.executeQuery(sql);
ResultSet rs = st.executeQuery(sql);
if(rs.next()){
String name = rs.getString("NAME");
System.out.println("name"+name);
}
connection.close();*/
} else {
System.out.println("串連oracle資料庫失敗!!!");
}


}
}

//要引入jdbc.jar包

https://files.cnblogs.com/files/cyz110/jdbc6.rar

jdbc+oracle測試類別。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.