map = new HashMap();
try {
String table = "testtable";
String url = "127.0.0.1";
String name = "name";
String password = "password";
String port = "1521";
String parentId = "orcl";
String URL = "jdbc:oracle:thin:@" + url + ":" + port + ":" + parentId ;
String driverName = "oracle.jdbc.OracleDriver"; //加载驱动
Class.forName(driverName).newInstance();
Statement stmt= null;
ResultSet result = null;
PreparedStatement pstmt = null;
connection = DriverManager.getConnection(URL , name , password);
stmt = connection.createStatement();
pstmt = connection.prepareStatement("SELECT * FROM "+table);
result = pstmt.executeQuery();
while (result.next()) {//ID 和 NAME 是 查询table表中的字段
System.out.print(result.getInt("ID"));
System.out.print(result.getString("NAME"));
}
result.close();
stmt.close();
connection.close();
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
}
}