Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: passing jtable row values to an sql statement while looping through it

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default passing jtable row values to an sql statement while looping through it

    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.

    This is an algorithm of what I want to do:

    for(iterate through the jtable and pass each row values to the sql statement)
    {
    try
    {
    Class.forName(getDriver rows here);
    Connection con = DriverManager.getConnection(getDatabase url here, getUsername, getPassword);
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("select * from getTableName where field = getFieldName");
    while(rs.next())
    {
    System.out.println(rs.getString());
    }
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }
    The Question is can I achieve this? and Can someone give a clue to do this (codes will be welcome), or any other method to achieve this.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: passing jtable row values to an sql statement while looping through it

    Quote Originally Posted by greeninho View Post
    The Question is can I achieve this?
    What happened when you tried?

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: passing jtable row values to an sql statement while looping through it

    I ASKED IF IT IS FEASIBLE , THEN IF IT IS NOT BASED ON MY OWN ALGORITHM, CAN YOU PROFER ANY METHOD TO ACHIEVE SOMETHING LIKE THAT.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: passing jtable row values to an sql statement while looping through it

    We live in a world where new things happen all of the time, why don't you give it a shot and see what you come up with?
    Or some research and see what you find?

    Please check that your shift key is not stuck when you post to the forum

Similar Threads

  1. Replies: 21
    Last Post: November 27th, 2012, 10:58 PM
  2. JTable Row Color
    By ellias2007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 23rd, 2012, 01:29 PM
  3. JTable Row Color
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: October 8th, 2010, 03:59 PM

Tags for this Thread