JDBC实现调用Oracle存储过程(2)

public interface Statement extends Wrapper {}
public interface PreparedStatement extends Statement {}
public interface CallableStatement extends PreparedStatement {}1
2
3
Statement是用来执行不带参数的SQL语句。

Connection conn = null;
ResultSet rs = null;
Statement statement = null;
try {
    //加载
    Class.forName(driver);
    //连接
    conn = DriverManager.getConnection(url, username, password);
    //设置查询语句
    statement = conn.createStatement();
    statement.execute("select * from emp");
    //执行查询
    rs = statement.getResultSet();
    while(rs.next()){             
      System.out.println(rs.getObject(2)+"==>"+rs.getObject(1));
    }
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

PreparedStatement是用来执行带输入参数的SQL语句。

Connection conn = null;
ResultSet rs = null;
PreparedStatement statement = null;
try {
      //加载
      Class.forName(driver);
      //连接
      conn = DriverManager.getConnection(url, username,password);
      //设置查询语句
      statement = conn.prepareStatement("select * from emp where ename like ?");
      //设置参数
      statement.setString(1,"%S%");
      //执行查询
      rs = statement.executeQuery();
      while(rs.next()){
          System.out.println(rs.getObject(2)+"==>"+rs.getObject(1));
      }
}catch(){ 
}

Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/5a0a241d47a6e871147f2c74252f5856.html