我试图插入一个值到一个JDBC,我从一个组合框中获取一个值,我必须将其转换为一个int,但查询不是认识到它是一个int?它打印出来作为一个数字控制台。是一个普通的int int
下面是最能复制问题的代码示例。
我已经尝试将输入转换为字符串,然后解析它,但它仍然不会识别它。它就像它不会识别整数。 我有点难住。 感谢
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class AddingItemToComboBox implements ActionListener{
JButton click = new JButton("Click me");
JComboBox qty = new JComboBox();
public AddingItemToComboBox(){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
panel1.setSize(500,500);
click.addActionListener(this);
qty.setBounds(10,270, 150, 20);
qty.setSize(80,30);
qty.addItem(1);
qty.addItem(2);
qty.addItem(3);
panel1.add(qty);
panel1.add(click);
frame.add(panel1);
frame.setSize(300, 200);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == click){
int quan = (int)qty.getSelectedItem();
System.out.println(quan);
//Connection to database
// Here is the problem "quan"
con.insertProduct(qaun);
}
}
public static void main(String[] args){
AddingItemToComboBox aic = new AddingItemToComboBox();
}
}
错误: 异常在线程 “AWT-EventQueue的 - 0” java.lang.Error的:未解决的问题,编译: qaun不能被解析为一个变量
您的代码和问题似乎没有与JDBC有关。你能简化代码和问题到你有问题的部分吗? – 2013-04-24 20:11:25