jdbc 连接oracle调用表数据

来源:互联网 发布:手机led显示屏软件 编辑:程序博客网 时间:2024/05/22 03:49
import java.sql.*;public class TestJDBC {/** * @param args * @throws ClassNotFoundException  * @throws SQLException  */public static void main(String[] args)  {// TODO Auto-generated method stubConnection conn = null;Statement statement = null;ResultSet rSet = null;try {Class.forName("oracle.jdbc.driver.OracleDriver");conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","system","123456");statement = conn.createStatement();rSet = statement.executeQuery("select * from student");while (rSet.next()) {System.out.print(rSet.getInt("ID") + "  ");System.out.print(rSet.getString("NAME") + "  ");System.out.println(rSet.getInt("AGE"));}} catch (ClassNotFoundException e) {// TODO: handle exceptione.printStackTrace();} catch (SQLException e) {// TODO: handle exceptione.printStackTrace();} finally{try {if (rSet != null) {rSet.close();rSet = null;}if (statement != null) {statement.close();statement = null;}if (conn != null) {conn.close();conn = null;}} catch (SQLException e) {e.printStackTrace();}}}}


原创粉丝点击