473,386 Members | 1,832 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,386 software developers and data experts.

Unable to display data from database on a jtable

126 64KB
I dont know what is wrong with my code but i'm not able to display the data extracted from database on a jtable:(
here is my code

Expand|Select|Wrap|Line Numbers
  1.  Connection con = null;
  2.         try {
  3.             Class.forName("com.mysql.jdbc.Driver");
  4.             String conURL = "jdbc:mysql://localhost/dbname";
  5.             con = DriverManager.getConnection(conURL, "user", "pswrd");
  6.             Statement st = con.createStatement();
  7.             String query1 = "select name, date, login, logout from " + jTextField1.getText() + " where id = '" + jTextField2.getText() + "'";
  8.             ResultSet rs = st.executeQuery(query1);
  9.             while (rs.next()) {
  10. jTable1.setModel(DbUtils.resultSetToTableModel(rs));
  11.             }
  12.  
  13.             System.out.println(query1);
  14.         } catch (ClassNotFoundException | SQLException e) {
  15.              JOptionPane.showMessageDialog(null, e);
  16.         }
where jTextField1 gives table name and jTextField2 gives id value.
May 8 '13 #1
2 1911
r035198x
13,262 8TB
1.)What happens when you run the code?
2.)Don't create SQL by adding string together. Use a PreparedStatement to supply the values as parameters.
May 9 '13 #2
Rabbit
12,516 Expert Mod 8TB
I don't believe they will be able to use a prepared statement since the table name is one of the variables.

Having a variable table name is odd though. It makes me think your data is structured incorrectly and is not normalized.
May 9 '13 #3

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

Similar topics

2
by: Joe | last post by:
Hi, I have an asp.net script that connects to MS Access database and displays data in a table. For some reason I am do not know how to display data say in ascending order of column1. I have...
9
by: dennist685 | last post by:
Walkthrough: Creating a Web Page to Display Access Database Data I've started the above walkthrough. However, near the beginning it gives the following instructions To set permissions in the...
3
by: Stonesifer21 | last post by:
So far I have a datagrid that can display data from Sql DB. I also have the edit, update, and cancel buttons working properly once the data is already in the database. I am having difficulty...
1
by: geeteshss | last post by:
First i would like to thank those persons who helped me out in solving my earlier problems the present problem is that i am unable to display data in datagrid....... but the data is visible in...
7
by: nma | last post by:
Hi I'm trying to display data in a table list format but error message like this appear. What is wrong with the code? "Parse error: syntax error, unexpected '<' in C:\htdocs\...\MB2movieinfo.php...
0
by: nitin24x | last post by:
hi, i need help ...ASp.net i created one form including some labels and text boxes for example firstname, Lastname,city,country,phone no. etc and textboxes for each. i have one database,in that...
1
by: ganesh22 | last post by:
Hi, my requriment is i want to display data from database in ms.word? Iam using asp.net with C# bcoz iam inserting resume in sqlserver, so i want to display that resume in word
4
by: JuAn2226 | last post by:
Hi, can anyone help me . when my program starts there is numbers and time will be display in the form of visual basic. it will run continuesly .My problem here is i dont know how to display the data...
5
by: moizpalitanawala | last post by:
Hello friends, How to add data to JTable from a .txt file. I had seen this code from one of the tutorial from java.com. This code doesnt take any input. But shows what is written in the array....
3
by: Tim Streater | last post by:
I have this script of a few lines, which runs as expected when I do it from the command line. It does one select followed by one insert on an SQLite database. The db in question has permissions...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.