• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Java - Database example (JDBC)

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,
During this summer I am trying to learn a bit more about java - database relations. One of the examples which is supposed to be relatively easy looks like that:


Assumptions and prerequisites for this project:
There exist a database with following two tables:
PERSON [ PERSON_ID (Primary Column), LAST_NAME, FIRST_NAME, STREET, CITY ]
ORDER [ ORDER_ID (Primary Column), ORDER_NO, PERSON_ID ]
Input files to be processed:
Person.data – The file has Person ID, First Name, Last Name, Street, City separated by comma (‘,’).

Order.data – The file Order ID, Order Number and Person ID separated by pipe (‘I’) character. Person ID is present in both the files.


Write a Java program to:
Read the files (Person.data and Order.data) and populate the tables (PERSON and ORDER)
Fetch data from these two database tables (using plain JDBC) and print:
Persons with at least one Order
All Orders with First Name of the corresponding person (if available)

The problem is I have no idea how to "bite it".

First of all, how do you read files with a 'data' extension?
Secondly, is all the needed information provided?

Any help would be much appreciated.

Cheers,
Tage




 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles Karlnesky wrote:First of all, how do you read files with a 'data' extension?


Just the way you would any other text file I suspect, because that's what they usually are. Have you been supplied with them? If so, try to open them in Notepad - if that works, then they're regular text.

Secondly, is all the needed information provided?


Seems pretty good, but 'I have no idea how to "bite it"' isn't. What exactly are you having problems with?

Winston
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you read the file the same way, regardless of what the extension is. Extensions are just used to give people a hint of what's in the file. Traditionally, a file with a .pl extension is a perl file, but it doesn't have to be.

With all projects, the trick is to break it down into it's component parts. So, figure out some small part - like opening a file, reading it line by line, then printing that line out. The method should be generic enough to open any file - so perhaps you pass it a string with a file name. Then you can use the same method to open both files.

Once you can do that, instead of printing the lines, pass the line to some other method that can parse the line.


 
Charles Karlnesky
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for explaining the data extension. The Person.data and Order.data files were not provided nor was the database. Since the data might be any text files reading them shouldn't be a problem. However, as I said the database was not provided therefore the question is - how do I establish a connection which will manage to connect to any database once someone runs the application. Furthermore, how would the testing on my side look like?

1. Read the data files to the code storing them under particular rows and columns.
2. Now I have to push the data to a database using JDBC as far as I understood.

Can I create a database using MS access and then modify the created database through the java application? How do I connect to the new MS access database?

I realize those questions are trivial but I am very 'greengorn-ish' about connection between java and databases.

Cheers
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles Karlnesky wrote:Thank you for explaining the data extension. The Person.data and Order.data files were not provided nor was the database....However, as I said the database was not provided therefore the question is - how do I establish a connection which will manage to connect to any database once someone runs the application.


Well, first you have to create it. You've been given the tables, so what's your problem?

I suspect that this assignment has been made deliberately vague (except where it needs to be) to find out how good you are at doing things on your own.

And since we're not in the business of doing your work for you here, you need to explain in detail where you're having problems.

Furthermore, how would the testing on my side look like?


Ooof. Slow down, hoss. First, understand what you're being asked to do. The tests (and how good they are) will be directly proportional to that.

Can I create a database using MS access and then modify...


Quite possibly, but it sounds to me like you're leaping ahead to the "how" before you understand the WHAT.

My suggestion: download a free database like MySQL, get familiar with it, and get those tables sorted out.

Then try to add some rows to them and query some things with Java - and, providing the tables are correct, it probably doesn't even matter if it has anything to do with your assignment; just get used to writing some test programs that do any old thing with those tables.

Then start writing your project code.

Winston
 
Charles Karlnesky
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is what I needed to be honest. A brief description where to start.
Thank you!
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles Karlnesky wrote:Thank you!


You're most welcome. And good luck.

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic