Blog信息 |
blog名称:小鸟吹烟 日志总数:157 评论数量:424 留言数量:-1 访问次数:1256888 建立时间:2006年10月23日 |

| |
[数据库方面]Statement 文章收藏, 网上资源
tone 发表于 2007/3/13 11:22:09 |
(以下收集自网络)
1.
java.sql.Statement stmt = conn.createStatement();ResultSet r = stmt.executeQuery("SELECT a, b, c FROM Table1");while (r.next()){ // 打印当前行的值。 int i = r.getInt("a"); String s = r.getString("b"); float f = r.getFloat("c"); System.out.println("ROW = " + i + " " + s + " " + f);}
2.
PreparedStatement pstmt = con.prepareStatement("UPDATE table4 SET m = ? WHERE x = ?");
pstmt.setString(1, "Hi"); pstmt.setInt(2, i); int rowCount = pstmt.executeUpdate();
3, CallableStatement
{call 过程名[(?, ?, ...)]} 返回结果参数的过程的语法为:
{? = call 过程名[(?, ?, ...)]} 不带参数的已储存过程的语法类似:
{call 过程名}
CallableStatement cstmt = con.prepareCall("{call reviseTotal(?)}");cstmt.setByte(1, 25);cstmt.registerOutParameter(1, java.sql.Types.TINYINT);cstmt.executeUpdate();byte x = cstmt.getByte(1);
4.
create PROCEDURE testProc()500)this.width=500'> begin 500)this.width=500'> select * from proctest;500)this.width=500'> end ;
<!--调用存储过程就在这里配了-->500)this.width=500'> <sql-query name="getUser" callable="true">500)this.width=500'> <return alias="user" class="net.wj.proc.vo.UserVO">500)this.width=500'> 500)this.width=500'> <return-property name="id" column="id" />500)this.width=500'> <return-property name="name" column="name" />500)this.width=500'> <return-property name="age" column="age" />500)this.width=500'> <return-property name="address" column="address" />500)this.width=500'> </return>500)this.width=500'> <!--这里就是我们刚刚创建的存储过程名-->500)this.width=500'> {call testProc()}500)this.width=500'> </sql-query>500)this.width=500'></hibernate-mapping>500)this.width=500'>public void ExampleProc()500)this.width=500'>500)this.width=500'> 500)this.width=500'>{500)this.width=500'> Session ss=this.getSession();500)this.width=500'> List li=ss.getNamedQuery("getUser").list();500)this.width=500'> for(int i=0;i<li.size();i++)500)this.width=500'>500)this.width=500'> 500)this.width=500'>{500)this.width=500'> UserVO vo=(UserVO)li.get(i);500)this.width=500'> log.info("name:"+vo.getName());500)this.width=500'> log.info("age"+vo.getAge());500)this.width=500'> log.info("address"+vo.getAddress());500)this.width=500'> }500)this.width=500'> ss.close();500)this.width=500'> }
5.
Connection con=session.connection(); String procedure = "{call sms历史库存查询(?) }"; CallableStatement cstmt = con.prepareCall(procedure);
cstmt.setString(1,parameter.getProperty(StockCardDetail._ClientID));
ResultSet rs=cstmt.executeQuery(); |
|
|