I am using sql server and when i write this sql select statement it runs well when i use it in netbean it show error com.microsoft.sqlserver.jdbc.sqlserverexception:the column name count(pr) is not valid i write code below can any one help me
try{ String sql="SELECT count(status) from Sub_Data";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
if(rs.next()){
String count4=rs.getString("count(status)");
totall111.setText(count4);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e );
}
either change it to
SELECT count(status) as c from Sub_Data
...
rs.getInt ("c");
or just use the columnIndex
rs.getInt (1);
Edit
count
would return an Int not a String
Try this one
try{ String sql="SELECT count(status) from Sub_Data";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
if(rs.next()){
String count4=rs.getString(1);
totall111=Integer.valueOf(count4);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.