Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Populate a database using loops

  1. #1
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Post Populate a database using loops

    Hi I am relatively new to Java and I am only beginning to learn about SQL. I have some basic's down but I have been wondering is there a way that I can add data to my database using loops instead of having to physically code every row/column individually ?

    I have been searching for this topic on the net and cannot seem to find anything helpful...

    I would really appreciate any help/tips etc on this matter !!!

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,098
    Rep Power
    6

    Default Re: Populate a database using loops

    Well before you can do it with a loop, you need to have something that you can loop through. Say a Collection class or an array holding the data that you want to insert.

    Let me pass a question back at you to answer: where does the data come from? Or rather: where should the data be coming from?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Default Re: Populate a database using loops

    Cheers I am planning on using an array unless I need to use a collection etc.
    I am getting the data from different sources online and editing it to suit my programs needs. The data is of all the Top European Football(soccer) teams, this will be one table then another table containing players. I am currently sourcing all my data.
    It will contain aprrox 30 teams.
    Last edited by Castro__711; 01-06-2014 at 11:58 AM.

  4. #4
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Default Re: Populate a database using loops

    Does that help at all ?

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,098
    Rep Power
    6

    Default Re: Populate a database using loops

    Yes well, make sure to store the data you get from these online sources in a way that you can easily put that data in a PreparedStatement. I would stick the data in a simple class you create yourself, stick the objects in an ArrayList and then come insertion time loop through the list, feeding a PreparedStatement using the fields from the object as the value bindings.

    There are more automatic ways of doing it that require far less manual labor - one of them is the Java Persistence API in which you wouldn't even have to invoke any SQL. But that is quite advanced material I wouldn't touch yet until you've learned and fully understand how to do it "the hard way" - which is plain JDBC using a Connection and a PreparedStatement.
    Castro__711 likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Default Re: Populate a database using loops

    Ok thank you for your help :)
    I will probably be a while but I will post when I am successful. Take care.

Similar Threads

  1. populate jCombobox with database data
    By joeyxaza in forum JDBC
    Replies: 2
    Last Post: 01-06-2014, 10:09 AM
  2. Replies: 4
    Last Post: 04-22-2011, 07:24 PM
  3. Replies: 20
    Last Post: 03-22-2011, 04:02 AM
  4. populate jCombobox with database data
    By joeyxaza in forum JDBC
    Replies: 0
    Last Post: 01-19-2009, 04:30 PM
  5. how to populate html:select with values from database
    By sathya_k_83 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-07-2007, 10:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •