用ssh连接ORACLE数据库,用到的jar文件,application里面的字符串是什么...
发布网友
发布时间:2024-10-23 14:24
我来回答
共1个回答
热心网友
时间:3分钟前
我有一个ssh链接mysql数据库的例子,给你发过去你看一下,如果是oracle用的jar文件是class12.jar,我也一起给你发过去吧!!你把我的例子,改一下就行了!!!
不好意思,jar文件太大了,发不过去,我把ssh的jar删了,给你截了四张图,你看一下吧!!
连oracle数据库:
package com.test.jdbc;
import java.sql.*;
public class TestJDBC {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager
.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:SZSK", "scott", "tiger");
String sql = "select * from dept";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("deptno dname");
while(rs.next()) {
int deptno = rs.getInt("deptno");
String dname = rs.getString("dname");
System.out.println(deptno + " " + dname);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(rs != null) {
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt != null) {
try {
stmt.close();
stmt = null;
}catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null) {
try {
conn.close();
conn = null;
}catch(SQLException e) {
e.printStackTrace();
}
}
}
}
}