注册 登录
编程论坛 Oracle论坛

写 JDBC 的时候出现这种问题,请问如何解决

水浙江雪 发布于 2014-11-17 12:04, 3926 次点击
只有本站会员才能查看附件,请 登录

写JDBC的时候出现这种问题,请问如何解决
3 回复
#2
水浙江雪2014-11-17 12:05
请问这是什么原因
#3
love云彩2014-11-17 14:12
适配器不能构建连接,贴代码看看
#4
水浙江雪2014-11-17 15:16
回复 3 楼 love 云彩
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");
                //new oracle.jdbc.driver.OracleDriver();
                conn = DriverManager.getConnection("jdbc:oracle:thin:@10.200.192.88:1521:ORACLE", "scott", "tiger");
                stmt = conn.createStatement();
                rs = stmt.executeQuery("select * from dept");
                while (rs.next()) {
                    System.out.println(rs.getString("deptno"));
                    System.out.println(rs.getInt("deptno"));
                }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
1