473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem in populating jtable from database

126 64KB
Jtable does not display the 1st row of my DB table,
below is my code to populate the jtable -

Expand|Select|Wrap|Line Numbers
  1. try {
  2. Class.forName("com.mysql.jdbc.Driver");
  3.                     String conURL = "jdbc:mysql://localhost/biometric";
  4.  Connection con = DriverManager.getConnection(conURL, "root", "root");
  5. Statement st = con.createStatement();
  6. String query = "select sl,enrolladdr,employee_name from employee_details ";
  7. ResultSet rs = st.executeQuery(query);
  8. System.out.println(query);
  9. if (rs.next()) {
  10. Mymodel model = (Mymodel) MyDbUtils.resultSetToTableModel(rs);
  11. jTable1.setModel(model);
  12. }
  13.  
  14.  } catch (ClassNotFoundException | SQLException e) {
  15.   e.printStackTrace();
  16.   }
Jan 10 '14 #1
2 1488
r035198x
13,262 8TB
1.) You must close all connections in a finally block or use the try with resources construct.
2.) if (rs.next()) moves to the first record in your resultset. So if you are doing while(rs.next()) in the method resultSetToTableModel then you are skipping the first row because you are calling rs.next twice before accessing the data. Remove that if(rs.next()) check.
Jan 15 '14 #2
PreethiGowri
126 64KB
Removing if(rs.next()) worked for me, Thanks:)
Jan 17 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David Shorthouse | last post by:
HI is it posible to auto populate an access database.? I have 1 table structured Index_ID. - Index & auto number First_Name - Char50 Surname - Char50 Initals - Char50 Postcode - Char50...
1
by: bill tie | last post by:
I have two dropDownLists A and B outside a gridView. A selection made in ddlA causes ddlB to be populated with data from the database. The gridView is populated with data according to a...
4
by: MLH | last post by:
Would like to create a database named 20060602Data.mdb and populate it with the data in 31 local tables in the current running database. I would like to do it all with a single button click. Was...
16
by: Head In A Pan | last post by:
OK... I am now heading into day 3 of attempting to populate a database through my flash form!! I figure I need some help before I crack! I just can't get it to work at all... I am able to get...
0
by: mahesh123 | last post by:
Hi, I am new to use the crystal reports8.0. I am facing the problem regarding the database connection through the ADO Connection. Suppose my database name is "sample.pra"(due to some security...
0
by: xhermit | last post by:
I'm creating a wiki-style website with a mysql database. I'm not to this point yet, but I'm thinking ahead of when I'll need to start populating the database. Obviously the point is for users...
8
by: Annalyzer | last post by:
I'm trying to populate a combo box on a form by inserting this query: SELECT * FROM menu WHERE NOT submitted; into the Row Source property of the combo box control. The Row Source Type is...
6
Lensmeister
by: Lensmeister | last post by:
Hi, As a newbie here I hope someone cane help me. I have Acess 2003 and am making a database that holds records or football matches. I haven't created any relationships as yet. The main table...
1
by: Monomita Har | last post by:
0 down vote favorite I am facing a small problem regarding this topic.I had write a code to autofill textboxes from database values when I type a id value in the previous textfield.i.e.if I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.