标签:todo rgs generated ras get object turn this 设置
import java.sql.*; public class OracleHelper { // 测试连接函数 public static void main(String []args) { derbyHelper de=new derbyHelper(); String sql="select * from users"; List<Object[]> list=de.queryList(sql, null); for(int i=0;i<list.size();i++) { Object []obj=list.get(i); System.out.println(obj[1].toString()+" "+obj[2].toString()); } } // oracle连接属性设置 String driver="oracle.jdbc.driver.OracleDriver"; String url="jdbc:oracle:thin:@10.62.140.54:1521:oracle1"; String user="scott"; String passwd="1234"; // 连接类和接口定义 Connection ct; PreparedStatement ps; ResultSet rs; public OracleHelper() { try { Class.forName(driver); ct=DriverManager.getConnection(url,user,passwd); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public int Update(String sql,String []paras) { int count=0; try { ps=ct.prepareStatement(sql); // 注入参数 setParameters(paras); // 更新数据行数。 count=ps.executeUpdate() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ this.close(); } return count; } private void setParameters(String[] paras) throws SQLException { if(paras!=null && !paras.equals("")) { for(int i=0;i<paras.length;i++) { ps.setString(i+1, paras[i]); } } } public ResultSet query(String sql,String[] paras) { try { ps=ct.prepareStatement(sql); setParameters(paras); rs=ps.executeQuery(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ //不能关。 } return rs; } public void close() { try { if(rs!=null) rs.close(); if(ps!=null) ps.close(); if(ct!=null) ct.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:todo rgs generated ras get object turn this 设置
原文地址:https://www.cnblogs.com/LittleSpring/p/9329359.html