Java JDBC
1、JDBC源码如下:
package nankang.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class Main { /** * @param args */ public static void main(String[] args) { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl"; String user = "phonesurvey"; String password = "world"; Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); String sql = "select * from Agent"; pstm = conn.prepareStatement(sql); rs = pstm.executeQuery(); while (rs.next()) { String agentId = rs.getString("AgentId"); System.out.println(agentId); } System.out.println("成功"); } catch (Exception e) { System.out.println(String.format("失败,%s", e.getMessage())); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) { e.printStackTrace(); } } if (pstm != null) { try { pstm.close(); } catch (Exception e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } } } }
2、
3、
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。