create proc p_o
(@name varchar(20),@pwd varchar(20) output)
as
select @pwd = pwd from t_users
where name = @name
其中一个为传入参数,一个为传出参数
代码如下:
this.getHibernateTemplate().execute(
new HibernateCallback()
{
public Object doInHibernate(Session session) throws SQLException
{
SQLQuery query = (SQLQuery) session.createSQLQuery("{Call p_0(?,?)}");//调用存储过程
query.setString(0, "vvv");//这里为传入参数
//如何得到传出参数
query.executeUpdate();//执行
return null;
}
}
);
如何得到传出参数,请各位帮忙一下!
10 个解决方案
#1
query.executeUpdate();//执行
query.getString(1);//这里为传出参数
看看
query.getString(1);//这里为传出参数
看看
#2
CallableStatement cs=con.prepareCall("{call 过程名(?,?,?)}");
cs.set....(1,开始传值);
cs.set....(2,开始传值);
cs.registerOutParameter(3,Type.什么类型);
1、2代表输入参数。
3 代表输出参数
cs.set....(1,开始传值);
cs.set....(2,开始传值);
cs.registerOutParameter(3,Type.什么类型);
1、2代表输入参数。
3 代表输出参数
#3
并没有query.getString(1);这样的语句
#4
非常感谢你的回答!
我是想通过
SQLQuery query = (SQLQuery) session.createSQLQuery("{Call p_0(?,?)}");//调用存储过程
query.setString(0, "vvv");//这里为传入参数
//如何得到传出参数
query.executeUpdate();//执行
return null;
这种方式来调用的....
#5
//$Id: Query.java 10590 2006-10-17 08:57:22Z max.andersen@jboss.com $
package org.hibernate;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
/*
* @see org.hibernate.Session#createQuery(java.lang.String)
* @see org.hibernate.ScrollableResults
* @author Gavin King
*/
public interface Query {
public String getQueryString();
public Type[] getReturnTypes() throws HibernateException;
public String[] getReturnAliases() throws HibernateException;
public String[] getNamedParameters() throws HibernateException;
public Iterator iterate() throws HibernateException;
public ScrollableResults scroll() throws HibernateException;
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException;
public List list() throws HibernateException;
public Object uniqueResult() throws HibernateException;
public int executeUpdate() throws HibernateException;
public Query setMaxResults(int maxResults);
public Query setFirstResult(int firstResult);
public Query setReadOnly(boolean readOnly);
public Query setCacheable(boolean cacheable);
public Query setCacheRegion(String cacheRegion);
public Query setTimeout(int timeout);
public Query setFetchSize(int fetchSize);
public Query setLockMode(String alias, LockMode lockMode);
public Query setComment(String comment);
public Query setFlushMode(FlushMode flushMode);
public Query setCacheMode(CacheMode cacheMode);
public Query setParameter(int position, Object val, Type type);
public Query setParameter(String name, Object val, Type type);
public Query setParameter(int position, Object val) throws HibernateException;
public Query setParameter(String name, Object val) throws HibernateException;
public Query setParameters(Object[] values, Type[] types) throws HibernateException;
public Query setParameterList(String name, Collection vals, Type type) throws HibernateException;
public Query setParameterList(String name, Collection vals) throws HibernateException;
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException;
public Query setParameterList(String name, Object[] vals) throws HibernateException;
public Query setProperties(Object bean) throws HibernateException;
public Query setProperties(Map bean) throws HibernateException
public Query setString(int position, String val);
public Query setCharacter(int position, char val);
public Query setBoolean(int position, boolean val);
public Query setByte(int position, byte val);
public Query setShort(int position, short val);
public Query setInteger(int position, int val);
public Query setLong(int position, long val);
public Query setFloat(int position, float val);
public Query setDouble(int position, double val);
public Query setBinary(int position, byte[] val);
public Query setText(int position, String val);
public Query setSerializable(int position, Serializable val);
public Query setLocale(int position, Locale locale);
public Query setBigDecimal(int position, BigDecimal number);
public Query setBigInteger(int position, BigInteger number);
public Query setDate(int position, Date date);
public Query setTime(int position, Date date);
public Query setTimestamp(int position, Date date);
public Query setCalendar(int position, Calendar calendar);
public Query setCalendarDate(int position, Calendar calendar);
public Query setString(String name, String val);
public Query setCharacter(String name, char val);
public Query setBoolean(String name, boolean val);
public Query setByte(String name, byte val);
public Query setShort(String name, short val);
public Query setInteger(String name, int val);
public Query setLong(String name, long val);
public Query setFloat(String name, float val);
public Query setDouble(String name, double val);
public Query setBinary(String name, byte[] val);
public Query setText(String name, String val);
public Query setSerializable(String name, Serializable val);
public Query setLocale(String name, Locale locale);
public Query setBigDecimal(String name, BigDecimal number);
public Query setBigInteger(String name, BigInteger number);
public Query setDate(String name, Date date);
public Query setTime(String name, Date date);
public Query setTimestamp(String name, Date date);
public Query setCalendar(String name, Calendar calendar);
public Query setCalendarDate(String name, Calendar calendar);
public Query setEntity(int position, Object val); // use setParameter for null values
public Query setEntity(String name, Object val); // use setParameter for null values
public Query setResultTransformer(ResultTransformer transformer);
}
#6
//$Id: SQLQuery.java 10846 2006-11-18 04:21:05Z steve.ebersole@jboss.com $
package org.hibernate;
import org.hibernate.type.Type;
/**
* Allows the user to declare the types and select list injection
* points of all entities returned by the query. Also allows
* declaration of the type and column alias of any scalar results
* of the query.
*
* @author Gavin King
*/
public interface SQLQuery extends Query {
/**
* Declare a "root" entity, without specifying an alias
*/
public SQLQuery addEntity(String entityName);
/**
* Declare a "root" entity
*/
public SQLQuery addEntity(String alias, String entityName);
/**
* Declare a "root" entity, specifying a lock mode
*/
public SQLQuery addEntity(String alias, String entityName, LockMode lockMode);
/**
* Declare a "root" entity, without specifying an alias
*/
public SQLQuery addEntity(Class entityClass);
/**
* Declare a "root" entity
*/
public SQLQuery addEntity(String alias, Class entityClass);
/**
* Declare a "root" entity, specifying a lock mode
*/
public SQLQuery addEntity(String alias, Class entityClass, LockMode lockMode);
/**
* Declare a "joined" entity
*/
public SQLQuery addJoin(String alias, String path);
/**
* Declare a "joined" entity, specifying a lock mode
*/
public SQLQuery addJoin(String alias, String path, LockMode lockMode);
/**
* Declare a scalar query result
*/
public SQLQuery addScalar(String columnAlias, Type type);
/**
* Declare a scalar query. Hibernate will attempt to automatically detect the underlying type.
*/
public SQLQuery addScalar(String columnAlias);
/**
* Use a predefined named ResultSetMapping
*/
public SQLQuery setResultSetMapping(String name);
/**
* Adds a query space for auto-flush synchronization.
*
* @param querySpace The query space to be auto-flushed for this query.
* @return this, for method chaning
*/
public SQLQuery addSynchronizedQuerySpace(String querySpace);
/**
* Adds an entity name or auto-flush synchronization.
*
* @param entityName The name of the entity upon whose defined
* query spaces we should additionally synchronize.
* @return this, for method chaning
* @throws MappingException Indicates the given entity name could not be
* resolved.
*/
public SQLQuery addSynchronizedEntityName(String entityName) throws MappingException;
/**
* Adds an entity name or auto-flush synchronization.
*
* @param entityClass The class of the entity upon whose defined
* query spaces we should additionally synchronize.
* @return this, for method chaning
* @throws MappingException Indicates the given entity class could not be
* resolved.
*/
public SQLQuery addSynchronizedEntityClass(Class entityClass) throws MappingException;
}
#7
上面是两个相关类或接口的所有方法。。(出自Hibernate 3.1源码)
貌似没你要的方法......
推荐方法:
1,最常用的在配置文件中配置
参考: http://yzh.lin.blog.163.com/blog/static/800401820087683823121/
2,用session获得连接对象connection,然后用CallableStatement来实现参数传递..
参考: http://developer.51cto.com/art/200906/129702.htm
貌似没你要的方法......
推荐方法:
1,最常用的在配置文件中配置
参考: http://yzh.lin.blog.163.com/blog/static/800401820087683823121/
2,用session获得连接对象connection,然后用CallableStatement来实现参数传递..
参考: http://developer.51cto.com/art/200906/129702.htm
#8
非常感谢你的回答
#9
mark
#10
楼主你的问题解决了么,我现在遇到这样的问题了
#1
query.executeUpdate();//执行
query.getString(1);//这里为传出参数
看看
query.getString(1);//这里为传出参数
看看
#2
CallableStatement cs=con.prepareCall("{call 过程名(?,?,?)}");
cs.set....(1,开始传值);
cs.set....(2,开始传值);
cs.registerOutParameter(3,Type.什么类型);
1、2代表输入参数。
3 代表输出参数
cs.set....(1,开始传值);
cs.set....(2,开始传值);
cs.registerOutParameter(3,Type.什么类型);
1、2代表输入参数。
3 代表输出参数
#3
并没有query.getString(1);这样的语句
#4
非常感谢你的回答!
我是想通过
SQLQuery query = (SQLQuery) session.createSQLQuery("{Call p_0(?,?)}");//调用存储过程
query.setString(0, "vvv");//这里为传入参数
//如何得到传出参数
query.executeUpdate();//执行
return null;
这种方式来调用的....
#5
//$Id: Query.java 10590 2006-10-17 08:57:22Z max.andersen@jboss.com $
package org.hibernate;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
/*
* @see org.hibernate.Session#createQuery(java.lang.String)
* @see org.hibernate.ScrollableResults
* @author Gavin King
*/
public interface Query {
public String getQueryString();
public Type[] getReturnTypes() throws HibernateException;
public String[] getReturnAliases() throws HibernateException;
public String[] getNamedParameters() throws HibernateException;
public Iterator iterate() throws HibernateException;
public ScrollableResults scroll() throws HibernateException;
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException;
public List list() throws HibernateException;
public Object uniqueResult() throws HibernateException;
public int executeUpdate() throws HibernateException;
public Query setMaxResults(int maxResults);
public Query setFirstResult(int firstResult);
public Query setReadOnly(boolean readOnly);
public Query setCacheable(boolean cacheable);
public Query setCacheRegion(String cacheRegion);
public Query setTimeout(int timeout);
public Query setFetchSize(int fetchSize);
public Query setLockMode(String alias, LockMode lockMode);
public Query setComment(String comment);
public Query setFlushMode(FlushMode flushMode);
public Query setCacheMode(CacheMode cacheMode);
public Query setParameter(int position, Object val, Type type);
public Query setParameter(String name, Object val, Type type);
public Query setParameter(int position, Object val) throws HibernateException;
public Query setParameter(String name, Object val) throws HibernateException;
public Query setParameters(Object[] values, Type[] types) throws HibernateException;
public Query setParameterList(String name, Collection vals, Type type) throws HibernateException;
public Query setParameterList(String name, Collection vals) throws HibernateException;
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException;
public Query setParameterList(String name, Object[] vals) throws HibernateException;
public Query setProperties(Object bean) throws HibernateException;
public Query setProperties(Map bean) throws HibernateException
public Query setString(int position, String val);
public Query setCharacter(int position, char val);
public Query setBoolean(int position, boolean val);
public Query setByte(int position, byte val);
public Query setShort(int position, short val);
public Query setInteger(int position, int val);
public Query setLong(int position, long val);
public Query setFloat(int position, float val);
public Query setDouble(int position, double val);
public Query setBinary(int position, byte[] val);
public Query setText(int position, String val);
public Query setSerializable(int position, Serializable val);
public Query setLocale(int position, Locale locale);
public Query setBigDecimal(int position, BigDecimal number);
public Query setBigInteger(int position, BigInteger number);
public Query setDate(int position, Date date);
public Query setTime(int position, Date date);
public Query setTimestamp(int position, Date date);
public Query setCalendar(int position, Calendar calendar);
public Query setCalendarDate(int position, Calendar calendar);
public Query setString(String name, String val);
public Query setCharacter(String name, char val);
public Query setBoolean(String name, boolean val);
public Query setByte(String name, byte val);
public Query setShort(String name, short val);
public Query setInteger(String name, int val);
public Query setLong(String name, long val);
public Query setFloat(String name, float val);
public Query setDouble(String name, double val);
public Query setBinary(String name, byte[] val);
public Query setText(String name, String val);
public Query setSerializable(String name, Serializable val);
public Query setLocale(String name, Locale locale);
public Query setBigDecimal(String name, BigDecimal number);
public Query setBigInteger(String name, BigInteger number);
public Query setDate(String name, Date date);
public Query setTime(String name, Date date);
public Query setTimestamp(String name, Date date);
public Query setCalendar(String name, Calendar calendar);
public Query setCalendarDate(String name, Calendar calendar);
public Query setEntity(int position, Object val); // use setParameter for null values
public Query setEntity(String name, Object val); // use setParameter for null values
public Query setResultTransformer(ResultTransformer transformer);
}
#6
//$Id: SQLQuery.java 10846 2006-11-18 04:21:05Z steve.ebersole@jboss.com $
package org.hibernate;
import org.hibernate.type.Type;
/**
* Allows the user to declare the types and select list injection
* points of all entities returned by the query. Also allows
* declaration of the type and column alias of any scalar results
* of the query.
*
* @author Gavin King
*/
public interface SQLQuery extends Query {
/**
* Declare a "root" entity, without specifying an alias
*/
public SQLQuery addEntity(String entityName);
/**
* Declare a "root" entity
*/
public SQLQuery addEntity(String alias, String entityName);
/**
* Declare a "root" entity, specifying a lock mode
*/
public SQLQuery addEntity(String alias, String entityName, LockMode lockMode);
/**
* Declare a "root" entity, without specifying an alias
*/
public SQLQuery addEntity(Class entityClass);
/**
* Declare a "root" entity
*/
public SQLQuery addEntity(String alias, Class entityClass);
/**
* Declare a "root" entity, specifying a lock mode
*/
public SQLQuery addEntity(String alias, Class entityClass, LockMode lockMode);
/**
* Declare a "joined" entity
*/
public SQLQuery addJoin(String alias, String path);
/**
* Declare a "joined" entity, specifying a lock mode
*/
public SQLQuery addJoin(String alias, String path, LockMode lockMode);
/**
* Declare a scalar query result
*/
public SQLQuery addScalar(String columnAlias, Type type);
/**
* Declare a scalar query. Hibernate will attempt to automatically detect the underlying type.
*/
public SQLQuery addScalar(String columnAlias);
/**
* Use a predefined named ResultSetMapping
*/
public SQLQuery setResultSetMapping(String name);
/**
* Adds a query space for auto-flush synchronization.
*
* @param querySpace The query space to be auto-flushed for this query.
* @return this, for method chaning
*/
public SQLQuery addSynchronizedQuerySpace(String querySpace);
/**
* Adds an entity name or auto-flush synchronization.
*
* @param entityName The name of the entity upon whose defined
* query spaces we should additionally synchronize.
* @return this, for method chaning
* @throws MappingException Indicates the given entity name could not be
* resolved.
*/
public SQLQuery addSynchronizedEntityName(String entityName) throws MappingException;
/**
* Adds an entity name or auto-flush synchronization.
*
* @param entityClass The class of the entity upon whose defined
* query spaces we should additionally synchronize.
* @return this, for method chaning
* @throws MappingException Indicates the given entity class could not be
* resolved.
*/
public SQLQuery addSynchronizedEntityClass(Class entityClass) throws MappingException;
}
#7
上面是两个相关类或接口的所有方法。。(出自Hibernate 3.1源码)
貌似没你要的方法......
推荐方法:
1,最常用的在配置文件中配置
参考: http://yzh.lin.blog.163.com/blog/static/800401820087683823121/
2,用session获得连接对象connection,然后用CallableStatement来实现参数传递..
参考: http://developer.51cto.com/art/200906/129702.htm
貌似没你要的方法......
推荐方法:
1,最常用的在配置文件中配置
参考: http://yzh.lin.blog.163.com/blog/static/800401820087683823121/
2,用session获得连接对象connection,然后用CallableStatement来实现参数传递..
参考: http://developer.51cto.com/art/200906/129702.htm
#8
非常感谢你的回答
#9
mark
#10
楼主你的问题解决了么,我现在遇到这样的问题了