欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
}
}
相关标签: JDBC SQL