vector - When I try to get data from MySQL database to jtable same data repeats in the jtable -


try {             connection getconnection = getdatabase_connection.getconnection();             statement getsstatement = getconnection.createstatement();             resultset getresultset = getsstatement.executequery("select * ap_database.ap_details");             defaulttablemodel setdefaulttablemodel = (defaulttablemodel) jtable1.getmodel();             vector setvector = new vector();             while (getresultset.next()) { 

here set data resultset vector

                setvector.add(getresultset.getstring("s_no"));                 setvector.add(getresultset.getstring("ap_rm"));                 setvector.add(getresultset.getstring("ap_serial"));                 setvector.add(getresultset.getstring("ap_gname"));                 setvector.add(getresultset.getstring("ap_ci"));                 setvector.add(getresultset.getstring("ap_co"));                 setvector.add(getresultset.getstring("ap_edate"));                 setvector.add(getresultset.getstring("ap_issuedp"));                 setvector.add(getresultset.getstring("ap_remark"));                 setvector.add(getresultset.getstring("ap_status")); 

in add vector defaulttablemodel

                setdefaulttablemodel.addrow(setvector);                   jtable1.setmodel(setdefaulttablemodel);             } 

after first row of data repeats number of rows have in resultset.

        } catch (exception e) {             joptionpane.showmessagedialog(null, e.getmessage(), "error", joptionpane.error_message);         } 

first of need download rs2xml.jar file , add project folder , write code after resultset

defaulttablemodel setdefaulttablemodel = new defaulttablemodel(); jtable1.setmodel(dbutils.resultsettotablemodel(getresultset)); 

it work.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -