简体   繁体   中英

Mysql table not found

here is my query along with the java code..

 public ArrayList getProductinfo(int id){

     try{
        String query="SELECT product_name,product_description FROM product WHERE category_id = "+id;
        statement = connect.createStatement();
        result = statement.executeQuery(query);
        System.out.println("Successfull Query for info..");
    }catch(Exception e){
        System.out.println("Error in Query..");
        e.printStackTrace();
    }
     ArrayList<String> columnName = null;
    try{
        columnName = new ArrayList<String>();
         for(int i = 1 ; i <= result.getMetaData().getColumnCount(); i++){
                columnName.add(result.getMetaData().getColumnName(i));
            }
    }catch(Exception e){
        e.printStackTrace();
    }
    return columnName;

}

this function was called from this one:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:

         jTable1.removeAll();
    jTable1.setModel(new javax.swing.table.DefaultTableModel(
     new Object [][] {
},
null
));

    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    MyDatabaseHandler db=new MyDatabaseHandler();
    db.setConnection(null, null, null);
    ArrayList content=db.getProductinfo(1);
    model.addColumn("Image");
    model.addColumn("Description");
    Object[] rows=new Object[2];
    ResultSet result=db.getRset();

    try{
       while(result.next()){
           String ss="";

           int m=0;

          for(Object c : content){
              m++;
              if(m==1){
                  //rows[0]=result.getBlob(c.toString());
                  rows[0]=result.getString(c.toString());
              }else if(m==2){
                  ss+="Name:"+result.getString(c.toString()+"\n");
              }else if(m==3){
                  ss+="Description:"+result.getString(c.toString()+"\n");
              }else if(m==4){
                  ss+="Price:"+result.getString(c.toString()+"\n");
              }else if(m==5){
                  ss+="Quantity:"+result.getString(c.toString());
              }
          } 
          rows[1]=ss;
            //System.out.println(ss);
            model.addRow(rows);
        }
   }catch(Exception e){
        e.printStackTrace();
    }
}           

this executes as it should be in cmd but whenever I run this from the java class it gives me this error:

java.sql.SQLException:Column'product_description' not found

note: This very query works in cmd just fine and the column product_description is there and there is no mistake in spelling.if I give only one column name after the SELECT string such as SELECT product_description only then it executes normally...What am I doing wrong? Thanks in Advance.

'product_description' is a column name - not table name. You apparently either don't have such column or have a mistake in its name.

尝试这个:

String query="SELECT `product_name`,`product_description` FROM product WHERE category_id = "+id;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM