我在數據庫ID,字符串和字符串 3列,我想提取出來,並在view.I目前它正在使用Map<id,Map<String,String>>
但是當我每次插入id是獲取所有內部地圖元素(所有行)。我想要特定的id和相關Map<String,String>
被插入>。是否有任何解決方案僅使用Maps
以上述方式。與鍵/值對使物體
Map<Integer,Map<String,String>> map=new LinkedHashMap<Integer,Map<String,String>>();
Map<String,String> map1=new LinkedHashMap<String,String>();
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "root");
Statement statement=null;
ResultSet rs=null;
int id=0;
/*String get_PICTURE = "select img from test where id="+id;*/
try{
String getpic="select * from test2";
MObjects mobj=new MObjects();
statement = conn.createStatement();
rs = statement.executeQuery(getpic);
while(rs.next()){
id=rs.getRow();
mobj.setId(id);
Blob imageBlob = rs.getBlob(2);
imageBlob.length();
InputStream binaryStream = imageBlob.getBinaryStream(1,(int)imageBlob.length());
ByteArrayOutputStream bos=new ByteArrayOutputStream();
int b;
byte[] buffer = new byte[1024];
while((b=binaryStream.read(buffer))!=-1){
bos.write(buffer,0,b);
}
byte[] fileBytes=bos.toByteArray();
bos.close();
String text=rs.getString(3);
byte[] encoded=Base64.encodeBase64(fileBytes);
String encodedString = new String(encoded);
/*ModelMap map = new ModelMap();
map.put("image", encodedString);*/
map1.put(encodedString,text);
map.put(id,map1);
}
}catch(Exception e){
e.printStackTrace();
}finally {
}
return map;
雅我做samething吶while循環外while循環 – smith
您已經創建MAP1對象。 –
非常感謝你 – smith