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);
}
}
}
}
标签:jdbc,String,数据库,resultSet,connection,statement,Oracle,null From: https://www.cnblogs.com/erguai/p/16880754.html