直接上代码吧,只是因为上篇的心血来潮。总结哈
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class OracleTest { public static void main(String[] args) { ResultSet rs = null; Statement stmt = null; Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@192.254.13.13:1521:orclTest", "123456", "123456"); stmt = conn.createStatement(); rs = stmt.executeQuery("select * from t_service"); while(rs.next()) { System.out.println(rs.getString(1)); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if(rs != null) { rs.close(); rs = null; } if(stmt != null) { stmt.close(); stmt = null; } if(conn != null) { conn.close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } } }
差不多就这样吧