出現的問題:ORA-12705 invalid or unknown NLS parameter value specified
解決方法如下:
MyEclipse安裝檔案eclipse中的 Duser.language=en 改為 Duser.language=zh然後重新啟動myeclipse
連接配接參數如下:
[url=jdbc:oracle:thin:@localhost:1521:orcl]url:jdbc:oracle:thin:@localhost:1521:orcl[/url]
user:system(不要用sys去登陸因為sys隻能通過sysdba和sysoper)
password:輸入你的資料庫密碼
導入Oracle10g的驅動一般在Oracle安裝檔案中有(G:/oracle/product/10.2.0/db_1/jdbc/lib)
連接配接代碼如下:
import java.sql.*;
public class DB{
public static void main(String[] args) {
Connection conn = null;
Statement sm = null;
ResultSet rs = null;
String dbUrl = "jdbc:oracle:thin:@localhost:1521:orcl";// 定義了資料庫連接配接串
String user = "system";// 資料庫的使用者名
String password = "密碼";// 資料庫的使用者密碼
try {
Class.forName("oracle.jdbc.driver.OracleDriver");// 加載驅動程式
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(dbUrl, user, password);// 與url指定的資料源建立連接配接
} catch (SQLException e) {
e.printStackTrace();
}
try {
sm = conn.createStatement();// 采用Statement進行查詢
} catch (SQLException e) {
e.printStackTrace();
}
try {
rs = sm.executeQuery("select * from hr.employees");
} catch (SQLException e) {
e.printStackTrace();
}
try {
while (rs.next()) {
System.out.println(rs.getString(1) + "," + rs.getString(2)); // 列印字段資訊
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
sm.close();// 關閉Statement,其上的ResultSet也将關閉
} catch (SQLException e) {
e.printStackTrace();
}
}
}