WEB开发网
开发学院软件开发Java 单独的java程序连接oracle数据库实例 阅读

单独的java程序连接oracle数据库实例

 2012-12-03 14:28:45 来源:WEB开发网   
核心提示: /*** 单独的java程序连接oracle数据库* author:JavaAlpha* date :2012-12-3 12:02:44*/import java.sql.*;public class Test {public static void main(String[] args){String drive

 /**
* 单独的java程序连接oracle数据库
* author:JavaAlpha
* date :2012-12-3 12:02:44
*/
import java.sql.*;
public class Test {
public static void main(String[] args){
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@192.168.1.1:1521:orcl";
String user = "root";
String password = "123456";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
Statement statement = conn.createStatement();
String sql = "SELECT PASSWORD from USER WHERE id='test1'";

ResultSet rs = statement.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString("PASSWORD"));
}
rs.close();
conn.close();
} catch(ClassNotFoundException e) {
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}

Tags:单独 java 程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接