Java 如何处理不兼容的类型:int无法转换为ResultSet intv1=Integer.parseInt(lbl\u READING\u NUMBER.getText()); int n=Integer.parseInt(jLabel_CUBIC_METER.getText()); int x=0; 双点=.11; 双ans=0; 如果(n
错误消息是问题的良好指示器-返回int值而不是Java 如何处理不兼容的类型:int无法转换为ResultSet intv1=Integer.parseInt(lbl\u READING\u NUMBER.getText()); int n=Integer.parseInt(jLabel_CUBIC_METER.getText()); int x=0; 双点=.11; 双ans=0; 如果(n,java,netbeans,Java,Netbeans,错误消息是问题的良好指示器-返回int值而不是ResultSet int v1 = Integer.parseInt(lbl_READING_NUMBER.getText()); int n = Integer.parseInt(jLabel_CUBIC_METER.getText()); int x = 0; double point = .11; double ans = 0; if(n<10){ for(n
ResultSet
int v1 = Integer.parseInt(lbl_READING_NUMBER.getText());
int n = Integer.parseInt(jLabel_CUBIC_METER.getText());
int x = 0;
double point = .11;
double ans = 0;
if(n<10){
for(n=0;x<4;x++){
ans = x*point*100;
}
}
try{
if(n<10){
for(n=0;x<4;x++){
ans = x*point*100;
}
}
String sql ="UPDATE reading set Amount=? where Reading_Number=?";
ps = conn.prepareStatement(sql);
ps.setDouble(1, ans);
ps.setInt(2, v1);
rs =ps.executeUpdate(); //This line gives me error saying:
"Incompatible types: int cannot be converted to ResultSet"
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
executeUpdate
返回一个int值,该值表示更新了多少行。使用executeQuery
接收ResultSet
样品
int rows = ps.executeUpdate();
我如何在我的代码中实现这一点,先生,这是整数行。请指定先生。差不多就是这样。为什么你认为你需要一个
结果集
?请原谅我的问题,先生,因为我是netbeans新手,我只想知道在哪里将这整数行插入到我的代码中,因为这是一个executeUpdate。你尝试过替换返回吗我已经使用了executeQuery,但它给我一个sql异常,说:不能用executeQuery()发出数据操作语句.executeQuery
仅用于SELECT语句,而executeUpdate
用于UPDATE、INSERT和DELETE等数据操作语句。因此,请先使用executeUpdate
,然后使用executeQuery
检索结果集。安全;)仔细查看中的循环。我甚至不去猜测他们打算做什么:正如我写的,他们根本没有任何意义。
ps.executeUpdate(); // This will update the database and return the number of rows which were affected.
rs = ps.executeQuery("SELECT * etc..."); // This you use when you want to retrieve a ResultSet