在JDBC简单封装的基础上实现

public class UserDao{

  public static void testGetUser(String userName) throws Exception{

    Connection conn=null;

    CallableStatement callableStatement=null;

    ResultSet resultSet=null;

    try{

      conn=JdbcUtils.getConnetcion();

      String sql="{call addUser(?,?,?,?)}";//调用数据库addUser存储过程,有四个参数,最后一个参数是输出新数据的ID

      callableStatement=conn.prepareCall(sql);

      callableStatement.setString(1,"test");

      callableStatement.setDate(2,new java.sql.Date(System.currentTimeMillis()));

      callableStatement.setFloat(3,100f);

      callableStatement.registerOutParameter(4,Types.INTEGER);

      callableStatement.excuteUpdate();

      int id=callableStatement.getInt(4);//获得存储过程的输出参数值

    }finally{

      JdbcUtils.freeResource(resultSet,preparedStatement,conn);

    }

  }

}

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-01
  • 2021-07-16
  • 2021-09-20
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
相关资源
相似解决方案