熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

單獨的java程序連接oracle數據庫實例

2022-06-13   來源: JSP教程 

  /**
* 單獨的java程序連接oracle數據庫
* authorJavaAlpha
* date ::
*/
import javasql*;
public class Test {
public static void main(String[] args){
String driver = "oraclejdbcdriverOracleDriver";
String url = "jdbc:oracle:thin:@::orcl";
String user = "root";
String password = "";
try {
ClassforName(driver);
Connection conn = DriverManagergetConnection(url user password);
if(!connisClosed())
Systemoutprintln("Succeeded connecting to the Database!");
Statement statement = conncreateStatement();
String sql = "SELECT PASSWORD from USER WHERE id=test";

ResultSet rs = statementexecuteQuery(sql);
while(rsnext())
{
Systemoutprintln(rsgetString("PASSWORD"));
}
rsclose();
connclose();
} catch(ClassNotFoundException e) {
Systemoutprintln("Sorrycan`t find the Driver!");
eprintStackTrace();
} catch(SQLException e) {
eprintStackTrace();
} catch(Exception e) {
eprintStackTrace();
}
}
}


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20208.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.