Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

looping through a jtable and passing its row values to an sql statement

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a table in my database which I displayed in my GUI program using a JTable. The JTable contains driver, database URL, username, password, table name, and field name / Fields columns respectively. I want to loop through this JTable rows, get their values and pass it this sql statements.

E.g: if the first row have

com.mysql.jdbc.Driver, jdbc:mysql://localhost:3306/DBname, root, pass, TableName, FieldName

as the values of each field And the second row have the following as the values of each field.

com.mysql.jdbc.Driver, jdbc:mysql://localhost:3306/DBname3, root, pass3, TableName3, FieldName3

 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch! I added code tags to make your post easier to read.

I'm not sure what you are asking. Are you getting an error? Are you asking how to connect the Swing part to your database code?

Also, a piece of JDBC advice: try this with a PreparedStatement instead of a Statement. It lets you use a ? to substitute values each time you call it. Which is faster and clearer for this type of work.
 
Green Onyeji
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for re-organizing the code. And I have taken note of your correction. What I want to do is to try and implement the algorithm (I mean the code). The code is more like an algorithm of what i want to do. So i need help on writing the code to actually achieve something like that. Like I said earlier, I have a jtable which has database information. Each row of the database would have different databases like the first one could be for mysql, the second for ms access, the third for sqlite, the fourth for hsqldb, etc. So i want a code that will loop through this jtable of different databases, then get each row values(which is database and its information like the driver, table name, Field name, database address) and pass it to the sql statement. Why I am trying to do this, is that I created an application that would allow a user to add a database/ databases to this application. So the application which has to do with searching a database should be able to look at any database added and search through it. I do not know if there is any other way to do this, but if there is, I don't mind changing my method. But if not i hope to get answer to based on what i have asked. I hope my reply is clear, Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic