请看看这个代码,并告诉我在哪里,我错了:无法在Java获取从MS Access数据库数据
我只是想这是通过组合框选自服务的价格我MS Access数据库 并在文本字段
service_box=new JComboBox();
service_box.setSize(20,25);
service_box.addItem("Select a Service");
service_box.addItem("Hair Cut");
service_box.addItem("Facial");
service_box.addItem("Bleaching");
显示它.....
service_box.addItemListener(this);
add_bt.addActionListener(this);
...... ....
@Override
public void itemStateChanged(ItemEvent i){
service_name=(String)i.getItem();
}
@Override
public void actionPerformed(ActionEvent ie){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc.odbc:acescon");
String query= "Select price from service table where service="+service_name;
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
String price_value=rs.getString("price");
total_tf.setText(price_value);
}
catch(SQLException | ClassNotFoundException e){
}
}
虽然它不显示任何错误。
分贝含有3-列 1-ID -2-服务 3-价格
我使用while循环也试过。而(rs.next( )){String price_value = rs.getString(“price”);} – rvsingh42
It如果你在catch块或者System.out.println(e.getMessage())中做'e.printStackTrace();'会出现错误;' –