java - Error when trying to populate JTable from mysql using arraylist -


i have tried populate data mysql jtable

although got size of rows printed. couldnt figure out what's wrong on loop

used following code , got error mentioned in end. however, query works on dbms.

one select data database

public class search{  public arraylist<string []> select_by_book(){         arraylist<string []> data = new arraylist<>();      try {          string query="select * "                 + "from detail d "                 + "join user_editor_author uea on d.detail_id = uea.detail_id "                 + "join author on a.author_id = uea.author_id "                 + "join editor e on e.editor_id = uea.editor_id "                 + "join user u on u.user_id = uea.user_id"                 + "where d.reference_type = 'book'"                 + "and u.user_id="+loginandregister.id;          resultset rs = connect.get(query);         while(rs.next()){             string tmp[] ={rs.getstring(2),rs.getstring(3),rs.getstring(4),rs.getstring(5)                     ,rs.getstring(6),rs.getstring(7),rs.getstring(8),rs.getstring(9),rs.getstring(9),                     rs.getstring(10),rs.getstring(18),rs.getstring(20)};              data.add(tmp);         }         rs.close();         return data;     } catch (sqlexception ex) {         logger.getlogger(search.class.getname()).log(level.severe, null, ex);         return null;     } }      } 

populate table method on class table:

 public class searchgui{  defaulttablemodel dtm ; arraylist<string[]> database; search thissearch=new search();   private void populatetable(){          dtm=(defaulttablemodel)jtable.getmodel();         database = thissearch.select_by_book();        // system.out.println(thissearch.all_reference().size());          for(object data[]:database){             dtm.addrow(data);          }     }} 

the error got:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'd.reference_type = 'book'and u.user_id=1' @ line 1

mysql query

create table if not exists `author` (   `author_id` int(11) not null auto_increment,   `author_name` varchar(100) not null,   primary key (`author_id`) ) engine=innodb  default charset=latin1 auto_increment=7 ;  create table if not exists `detail` (   `detail_id` int(11) not null auto_increment,   `title_name` varchar(200) default null,   `issn` varchar(150) default null,   `volume` varchar(100) default null,   `issue` varchar(100) default null,   `start_page` int(11) default null,   `end_page` int(11) default null,   `year` varchar(4) default null,   `location` varchar(200) default null,   `publisher` varchar(200) not null,   `reference_type` varchar(200) not null,   `user_id` int(10) not null,   primary key (`detail_id`) ) engine=innodb  default charset=latin1 auto_increment=12 ;  create table if not exists `editor` (   `editor_id` int(11) not null auto_increment,   `editor_name` varchar(100) not null,   primary key (`editor_id`) ) engine=innodb  default charset=latin1 auto_increment=10 ;  create table if not exists `user` (   `user_id` int(11) not null auto_increment,   `user_name` varchar(100) not null,   `user_email` varchar(100) not null,   `user_username` varchar(100) not null,   `user_password` varchar(100) not null,   primary key (`user_id`) ) engine=innodb  default charset=latin1 auto_increment=5 ; 

the first row of table has checkbox not others. so, havent populated first column.

what mean haven't populated first column? using addrow(...) method add data tablemodel, first column have data first entry in array.

i couldnt figure out what's wrong on loop

dtm.addrow(new object[]{i+1,data[1]}); 

the first object in array integer, not boolean.

i have tried populate data mysql jtable. first row of table has checkbox not others.

that not way tables work. data needs consistent in columns, otherwise need customize jtable behaviour.

unless post demo code (with hard coded data because don't have access database) attempts show doing can't provide real suggestions.

edit:

here example of sscce works:

import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.table.*;  public class sscce extends jpanel {     public sscce()     {         defaulttablemodel model = new defaulttablemodel(0, 3);         model.addrow( new object[] { "1", "2", "3" } );         model.addrow( new object[] { "one", "two", "three" } );          jtable table = new jtable(model);         add( new jscrollpane(table) );     }      private static void createandshowgui()     {         jframe frame = new jframe("sscce");         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.add(new sscce());         frame.setlocationbyplatform( true );         frame.pack();         frame.setvisible( true );      }      public static void main(string[] args)     {         eventqueue.invokelater(new runnable()         {             public void run()             {                 createandshowgui();             }         });     } } 

post sscce doesn't work can see data trying load tablemodel. how simplify problem can understand doing. again database irrelevant.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -