public String getNameById(String sql) throws DataAccessException {
String name="";
log.debug("sql:"+sql);
Session session = null;
try {
session = this.getHibernateTemplate().getSessionFactory().openSession();
Connection conn = session.connection();
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
name = res.getString(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
session.close();
}
return name;
}
String hql = "select agent_No from agent_info where agent_id='"
+ agent.getAgentId().substring(0, 3) + "'";agent_NO字段字数据库是number类型。
agent_id在数据库的类型是varchar2.上面的方法调用这样的hql,返回类型是String,可以吗。
你可以得到后在转为String类型的。
你直接这样接收应该不行吧.
create table AGENT_INFO
(
AGENT_NO NUMBER(10) not null,
AGENT_ID VARCHAR2(144) not null,
AGENT_NAME VARCHAR2(100),
AGENT_LEVEL NUMBER(4),
.........................
alter table AGENT_INFO
add constraint AGENT_INFO_PK primary key (AGENT_NO)
using index
tablespace PBM_MED_IDX
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 2M
minextents 1
maxextents unlimited
pctincrease 0
);
项目使用的技术是hibernate JSF spring。