How to insert rows in sql database from excel?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • diawi883
    New Member
    • Jan 2008
    • 5

    How to insert rows in sql database from excel?

    Hi!
    I don't have a clue how to solve this problem in a simple way. I'm using a jdbc driver. The task is to compare rows in the excel sheet and insert them if they don't exists in the database. How can i do this? :S

    Very graceful for any answer i can get :)

    //Diana
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by diawi883
    Hi!
    I don't have a clue how to solve this problem in a simple way. I'm using a jdbc driver. The task is to compare rows in the excel sheet and insert them if they don't exists in the database. How can i do this? :S

    Very graceful for any answer i can get :)

    //Diana
    Your best bet is to split the problem into steps.
    First you need to be able to read an excel document.
    Then you need to be able to read data from a database.
    The third step is the comparison between the data from the excel sheet and what's already in the database.
    Finally you need to be able to perform insert statement on the database.

    If you know JDBC then the problem is as good as solved.
    Is there any particular step that you are stuck on now?

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Originally posted by diawi883
      Hi!
      I don't have a clue how to solve this problem in a simple way. I'm using a jdbc driver. The task is to compare rows in the excel sheet and insert them if they don't exists in the database. How can i do this? :S

      Very graceful for any answer i can get :)

      //Diana
      The first step is to break the problem into pieces and analyze each piece. I see at least three steps:

      1. Reading from an Excel spreadsheet
      2. Comparing row data
      3. Database operations

      edit: punchbug!

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by BigDaddyLH
        ...

        edit: punchbug!
        And I was typing the whole thing in zero's and ones too ...

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Originally posted by r035198x
          And I was typing the whole thing in zero's and ones too ...
          Typing? You have a keyboard? Luxury! I did it all by connecting and unconnecting cables. But try telling that to young people today...

          Comment

          • diawi883
            New Member
            • Jan 2008
            • 5

            #6
            Hi again :)
            I can read from the exceldocument and from the database but i don't know how to store the data from the excelsheet (should i keep it in a array or something? :S) and then how I write the current string from the excel into the database?

            /diana

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by diawi883
              Hi again :)
              I can read from the exceldocument and from the database but i don't know how to store the data from the excelsheet (should i keep it in a array or something? :S) and then how I write the current string from the excel into the database?

              /diana
              You can keep the data in any structure you want. Probably in dynamic collections.
              For writing to the database, just do something similar to what you did to read the data, only this time you use executeUpdate instead of executeQuery. Just check the API docs for those methods.

              Comment

              • BigDaddyLH
                Recognized Expert Top Contributor
                • Dec 2007
                • 1216

                #8
                On the database side, it sounds like you don't know about JDBC. Take the tutorial:

                This JDBC Java tutorial describes how to use JDBC API to create, insert into, update, and query tables. You will also learn how to use simple and prepared statements, stored procedures and perform transactions

                Comment

                • diawi883
                  New Member
                  • Jan 2008
                  • 5

                  #9
                  Ok thanks for the help, I'll read about the JDBC and then hope I'll understand it some more :)

                  /Diana

                  Comment

                  Working...