2015/7/28问题集
json转化异常
异常信息为:Expected BEGIN_ARRAY but was BEGIN_OBJECT
说不是数组,查找到当时的json数据.
{“id”:0,”name”:”zsz”,”age”:22,”goalTime”:”2015/7/28”,”goalWeight”:0.0,”height”:2.0}
这并不是一条数组信息
不管你有几条数据:他都要是一个数组类型。也就是返回的是一个list集合。
[{“id”:0,”name”:”zsz”,”age”:22,”goalTime”:”2015/7/28”,”goalWeight”:0.0,”height”:2.0}]
修改方法 ###添加的时候、不要在for循环里添加。
listDataBeans=dataDao.getEditData(jsonNameStr);
for (int i = 0; i < listDataBeans.size(); i++) {
DataBean dataBean=listDataBeans.get(i);
System.out.println(dataBean.getGoalTime()+"傻逼");
}
dataString = gson.toJson(listDataBeans);
JDBC查询之感悟
查询必定是通过一个条件来查找,返回的数据可能会有多条(List)。
查询出来是一个ResultSet,所以也需要一条一条读取出来。有值得时候就设置进属性。
public ArrayList<ManBean> getAllMan(String name) {
boolean b=false;
ArrayList<ManBean> arrayList=new ArrayList<ManBean>();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
String getAllManSQL="SELECT * FROM man "+"WHERE name=?";
try {
conn=BaseConnection.getConnection();
ps=(PreparedStatement) conn.prepareStatement(getAllManSQL);
ps.setString(1, name);
System.out.println(ps+")))))"+name);
rs=ps.executeQuery();
String line;
StringBuffer sb=new StringBuffer();
while (rs.next()) {
ManBean manBean=new ManBean();
manBean.setArm(rs.getString("arm"));
manBean.setChest(rs.getString("chest"));
manBean.setImage(rs.getBytes("image"));
manBean.setTime(rs.getString("time"));
manBean.setName(rs.getString("name"));
manBean.setWeight(rs.getString("weight"));
manBean.setWaust(rs.getString("waust"));
manBean.setId(rs.getInt("id"));
arrayList.add(manBean);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
BaseConnection.closeResource(rs, ps, conn);
}
return arrayList;
}
JDBC等一干操作
@Override
public boolean deleteMan(int id) {
boolean b=false;
Connection conn=null;
PreparedStatement ps=null;
String deleteManSQL="DELETE FROM man WHERE id=?";
try {
conn=BaseConnection.getConnection();
ps=(PreparedStatement) conn.prepareStatement(deleteManSQL);
ps.setInt(1, id);
System.out.println(deleteManSQL);
int i=ps.executeUpdate();
if (i>0) {
b=true;
}
} catch (Exception e) {
e.printStackTrace();
}finally {
BaseConnection.closeResource(ps, conn);
}
return b;
}