jdbc的简单使用
程序员文章站
2022-05-28 18:00:46
...
ResultSet result=null;
Connection con=null;
Statement sql=null;
try{
con = pfwClient.getDataSource().getConnection();
sql = con.createStatement();
result = sql.executeQuery(sqlStatement);
int cols = result.getMetaData().getColumnCount();
if("Y".equals(type)){
Vector rs = new Vector();
int i;
while(result.next()){
RecordBean rb = new RecordBean();
for(i=1;i<=cols;i++){
rb.set(result.getMetaData().getColumnName(i),result.getString(i));
}
rs.add(rb);
}
if(null!=varName){
map.put(varName[0], rs);
}
}else if("N".equals(type)){
while(result.next()){
for(int k=0;k<length;k++){
if(!"".equals(tableColumn[k])){
tableColumnValue[k] = result.getString(tableColumn[k]);
map.put(varName[k],tableColumnValue[k]);
}
}
break;
}
}
}catch(SQLException e){
System.out.println("Please check sql is correct in DataService");
e.printStackTrace();
}finally{
try{
if(sql != null)
sql.close();
if(con != null){
con.close();
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
上一篇: php把数组值转换成键的方法_php技巧
下一篇: 基于HTML5 的互联网+地铁行业