67,513
社区成员
发帖
与我相关
我的任务
分享
public String[] getFriendTeleByName(String name) {
Connection conn=this.getDBconn();
//String tele=null;
//String name1=null;
//String frd_email=null;
String add_list[]=new String[3];
if (conn==null)
return null;
try{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from friends where frd_name='"+name+"'");
if (rs.next()){
add_list[0]= rs.getString("frd_tele");
add_list[1]=rs.getString("frd_name");
add_list[2]=rs.getString("frd_email");
}else
rs.close();
stmt.close();
conn.close();
return add_list;
}catch (Exception ex) {
ex.printStackTrace();
return null;
}
定义了一个add_list数据,把取出来的数据放进数组中,然后return出结果,但是一直报java.lang.NoSuchMethodError
public String getFriendTeleByName(String name) {
Connection conn=this.getDBconn();
String tele=null;
String name1=null;
String frd_email=null;
if (conn==null)
return null;
try{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from friends where frd_name='"+name+"'");
if (rs.next()){
tele= rs.getString("frd_tele");
name1=rs.getString("frd_name");
frd_email=rs.getString("frd_email");
}else
rs.close();
stmt.close();
conn.close();
return tele;
}catch (Exception ex) {
ex.printStackTrace();
return null;
}
这是最初代码,可以return出tele的值,查了一下return不能返回多个子,于是想到了上面的这段数组