jdbc连接Oracle数据库

import java.sql.*;

public class Main {
    public static void main(String[] args) {

        System.out.println("Hello world!");
        Connection connection = null;
        Statement statement = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.235:1521:orcl","test_levle1","dbcloud");
            System.out.println(connection);
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT * FROM sc where SID = '03'");
            while (resultSet.next()){
                String sid = resultSet.getString("SID");
                String cid = resultSet.getString("CID");
                String source = resultSet.getString("SCORE");
                System.out.println(sid+"==="+cid+"==="+source);
            }


        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            try {
                if(statement!=null){
                    statement.close();
                }
                if(connection != null){
                    connection.close();
                }

            } catch (SQLException e) {
                throw new RuntimeException(e);
            }

        }
    }
}

 

posted @ 2022-11-11 15:54  我是小二  阅读(269)  评论(0)    收藏  举报