问题如下
public Account queryByaccount1(String account) throws SQLException {
Account acc = null;
Connection conn = this.getConnection();
PreparedStatement st = conn.prepareStatement("{call account_ExistUser(?)}");
st.setString(1, account);
ResultSet rs = st.executeQuery() ;
//怎样将rs里的数据写入acc中,下面是我写的,可是不行!请问怎么写?
while(rs.next())
{
acc.setId(rs.getInt(1));
acc.setUsername(rs.getString(2));
acc.setpwd(rs.getString(3));
}
return acc;
}
如果可以的话,给个完整的例子~~~ 谢谢了~~~~
[b]问题补充:[/b]
我看了,可是不是很明白~~
请lovewhzlq (资深架构师) 能以我这个例子写一次麽?~
`
根据用用户名account取得数据库的这条内容。
public Account queryByaccount1(String account) throws SQLException {
Account acc = null;
Connection conn = this.getConnection();
CallableStatement st = conn.prepareCall("{call account_ExistUser(?)}");
st.setString(1, account);
st.execute() ;
ResultSet rs = (ResultSet) toesUp.getObject(1);
while(rs.next())
{
acc.setId(rs.getInt(1));
acc.setUsername(rs.getString(2));
acc.setpwd(rs.getString(3));
}
return acc;
}
要用CallableStatement 这个
看例子
http://blog.csdn.net/deyinchan/archive/2008/09/23/2968008.aspx
http://developer.51cto.com/art/200907/134905.htm
public Account queryByaccount1(String account) throws SQLException {
Account acc = null;
Connection conn = this.getConnection();
CallableStatement st = conn.prepareCall("{call account_ExistUser(?)}");
st.setString(1, account);
st.execute() ;
}
问题是你的存储过程返回什么类型的数据???
如果不返