jsp的List出现问题
import java.sql.*;
import java.util.*;
import future.GetInfoFromDB;//从数据库读取数据的类
public class search {
public Map getEnameCard(String s)throws
SQLException{
GetInfoFromDB gi=new GetInfoFromDB();
List l;
//getList方法是从数据库读取结果集并封装到List
l=gi.getList( "select*from enamecard where user=\ " "+s+ "\ " ");
Map m=(Map)l.get(0);
return m;
}
public static void main(String[] args)throws SQLException{
search se=new search();
Map m1=se.getEnameCard( "用户1 ");
Map m2=se.getEnameCard( "用户2 ");
System.out.print(m1.get( "user "));
System.out.print(m2.get( "user "));
}
本来结果应该显示用户1 用户2,可是运行后都是显示用户1,这是为什么阿?为什么第二次调用方法getEnameCard(),List没有改变啊?
------解决方案--------------------search se=new search();
Map m1=se.getEnameCard( "用户1 ");
search se1=new search();
Map m2=se1.getEnameCard( "用户2 ");
System.out.print(m1.get( "user "));
System.out.print(m2.get( "user "));