Results 1 to 7 of 7
  1. #1
    middlewaredev is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default How to read a Log file and map the data to a table in an RDBMS?

    Hello please help me with this..

    I have a log file,... i want to read the data from the log file which shows how many requests are there ... the code must be in such a way that there should be an hourly stats mapped to a database , typically an oracle database...

    The req. is to take the data from the log file..
    split the data in such a way that there is Date Stamp, Number of requests, time
    This should occur each and every hour.. we must get how many requests there were to the server in the previous hour.. and that number of requests and the time should be mapped to columns in a database table..

    Someone please help me.. Please give me the code.. or atleast please give me some brief specifics about how to achieve this... and how to do it...

    Thank you very much!
    Last edited by middlewaredev; 06-03-2011 at 06:27 AM. Reason: making it more professional

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by middlewaredev View Post
    Please give me the code..
    We don't do it here. If you have tried and got stuck up somewhere, we would be happy to help you out.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    middlewaredev is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    I dont need the entire code... yes i do i have a code... its using FileInputStream to parse the data... but i need to do it from scratch again because that is not good enough.. .please give me a methodology about what can be done.. what classes, methods can be used... can you please give me a brief idea about what to do...

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by middlewaredev View Post
    yes i do i have a code...
    Show it here. What are you doing and what "else" you want to do? No one here can predict what you might have done till now.

    Hope that makes sense,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    middlewaredev is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Actually I wrote

    FileInputStream fls = new fileinputstream(file.log);

    Then i wrote some getter setter methods to get the data to the pojo... that's all...



    now i need to know how to get the individual data into objects to map them to the database

  6. #6
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by middlewaredev View Post
    The req. is to take the data from the log file..
    split the data in such a way that there is Date Stamp, Number of requests, time
    You can use a BufferedReader for this. That can read the log file line by line and save it in a String. Then if the elements that you want are separated in a standard way, you can collect them using the String.split method and use them later on...

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    You will also need to write a class that represents the data on each of those lines, and then you'll use the stuff you've read in (see Goldests post above) to create an object for that line.
    Then you'll pass that object to the database code (a DAO of some sort) to save it to the database.
    You will do this for each line.
    Do not read in the entire file, creating all the objects and then saving them. This could well result in an out of memory error.

    So...
    1. Read line
    2. Create object
    3. Save object
    4. Back to 1.

Similar Threads

  1. read table data from javamail
    By jeev81 in forum Advanced Java
    Replies: 7
    Last Post: 05-19-2011, 04:48 PM
  2. Replies: 2
    Last Post: 03-25-2011, 02:36 PM
  3. Replies: 1
    Last Post: 11-09-2010, 09:28 AM
  4. Need a solution to read and store data from a file
    By sheetalnri in forum New To Java
    Replies: 10
    Last Post: 09-30-2010, 06:43 AM
  5. Replies: 0
    Last Post: 04-17-2008, 07:36 PM

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
  •