当前位置: 技术问答>java相关
如果记录中某字段值为null, select的时候会出错?怎吗办?
来源: 互联网 发布时间:2015-11-11
本文导语: statement=connection.prepareStatement("INSERT INTO concept values (?,?,?,?)"); statement.setString(1,tempCon.GetConId()); statement.setString(2,tempCon.GetConName()); statement.setString(3,tempCon.GetDetails()); statement.set...
statement=connection.prepareStatement("INSERT INTO concept values (?,?,?,?)");
statement.setString(1,tempCon.GetConId());
statement.setString(2,tempCon.GetConName());
statement.setString(3,tempCon.GetDetails());
statement.setString(4,tempCon.GetImagePath());
statement.executeUpdate();
statement.clearParameters();
statement = connection.prepareStatement("select * from concept");
resultSet=statement.executeQuery();
while(resultSet.next()){
String strId=resultSet.getString("Id");
String strName=resultSet.getString("NodeName");
String strDetails=resultSet.getString("Details");
String strImagePath=resultSet.getString("ImageInfo");
如果为null, getString()的时候会发生异常!
statement.setString(1,tempCon.GetConId());
statement.setString(2,tempCon.GetConName());
statement.setString(3,tempCon.GetDetails());
statement.setString(4,tempCon.GetImagePath());
statement.executeUpdate();
statement.clearParameters();
statement = connection.prepareStatement("select * from concept");
resultSet=statement.executeQuery();
while(resultSet.next()){
String strId=resultSet.getString("Id");
String strName=resultSet.getString("NodeName");
String strDetails=resultSet.getString("Details");
String strImagePath=resultSet.getString("ImageInfo");
如果为null, getString()的时候会发生异常!
|
public String NullToSp(String Col) {
if (Col == null)
return "";
else
return Col.trim();
}
String strName=NullToSp(resultSet.getString("NodeName"));
if (Col == null)
return "";
else
return Col.trim();
}
String strName=NullToSp(resultSet.getString("NodeName"));