我希望java中的结果值与IBM Data Studio中的Int一样,但在我的情况下是java生成double值,我不知道为什么?,请帮忙修复它!
private void polDatToTab(ResultSet rs, JTable table) throws SQLException{
String[] colHead = new String[] {"No","NIK","Nama"};
DefaultTableModel tm = new DefaultTableModel();
ResultSetMetaData rsd = rs.getMetaData();
Vector<String> nameCol = new Vector<String>();
int kolCount = rsd.getColumnCount();
for(int i=0;i<colHead.length;i++){
nameCol.add(colHead[i]);
}
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while(rs.next()){
Vector<Object> vec = new Vector<Object>();
for(int j=1;j<=kolCount;j++){
vec.add(rs.getObject(j));
}
data.add(vec);
}
tm.setDataVector(data, nameCol);
table.setModel(tm);
}
private void srcEmp(){
String srcE = "SELECT (@ROW_NUMBER:=@ROW_NUMBER + 1) AS No_Urut,NIK,NAMA FROM PAYROLL.KARYAWAN,"
+ "(SELECT @ROW_NUMBER:=0) AS T WHERE NAMA LIKE '%"+srcRes+"%'";
DbConnect co = new DbConnect();
co.connectDB();
try {
st = co.connection.createStatement();
ResultSet ul = st.executeQuery(srcE);
polDatToTab(ul, tabResSrc);
} catch (SQLException ex) {
Logger.getLogger(ResSrc.class.getName()).log(Level.SEVERE, null, ex);
}
}
SELECT (@ROW_NUMBER:=@ROW_NUMBER + 1) AS No_Urut,NIK,NAMA
FROM PAYROLL.KARYAWAN,(SELECT @ROW_NUMBER:=0) AS T
WHERE NAMA LIKE '%"+srcRes+"%'
答案 0 :(得分:1)
您的polDatToTab
方法并不通用,看起来它只能用于此特定结果集。由于这一行,我正在跳到那个结论
String[] colHead = new String[] {"No","NIK","Nama"};
因此,您知道第一列应该是一个int。因此,
vec.add(rs.getInt(1));
for(int j=2; j<=kolCount; j++){
vec.add(rs.getObject(j));
}
技巧