我正在尝试从 J 组合框中进行选择,并使用它从数据库中查找表。但出现了错误:
我的代码:
JButton btnGo = new JButton("Go!");
btnGo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Connection conni = null;
ResultSet rs=null;
PreparedStatement pst=null;
try{
Class.forName("org.sqlite.JDBC");
conni = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//TireShop.sqlite");
String x = comboBox.getSelectedItem().toString();
String sql="select * from " + x;
pst=conni.prepareStatement(sql);
rs=pst.executeQuery();
while(rs.next()){
String name = rs.getString("Namet");
nameofguy.setText(rs.getString(name));
}
}catch(Exception i){
JOptionPane.showMessageDialog(null, i);
}
我正在搜索表格..但它说找不到列。
最佳答案
这就是你的问题
while(rs.next()){
String name = rs.getString("Namet");
//rs.getString returns Ayaan. So value of name is "Ayaan"
nameofguy.setText(rs.getString(name));
// Youre trying to get the value corresponding to the column Ayaan here
//This is why the exception is thrown as there is no column called Ayaan
}
相反
while(rs.next()){
String name = rs.getString("Namet");
nameofguy.setText(name);
}
关于java - Sqlite 列确定错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31815472/