aspose file tools*
The moose likes JDBC and the fly likes offtopic for cert but related to java basics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "offtopic for cert but related to java basics" Watch "offtopic for cert but related to java basics" New topic
Author

offtopic for cert but related to java basics

mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
this may not be scjp related but certainly at one point or other you would encounter this.
i was asked (interview) about a sql operation done via java. and i had to say i don't know.
please guide me to a simple example where i can write a simple 5 line program that can interact with a Database server to send and retrive a record or create a record. (i was told that this program is 5 lines).
web links, discussion forums, (on this ranch as well), or any other info please let me know. if this offtopic please move this thread to the relevant group. but in any case this is my email address and you can write to me. markstone23@yahoo.com
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by mark stone:
this may not be scjp related but certainly at one point or other you would encounter this.
i was asked (interview) about a sql operation done via java. and i had to say i don't know.
please guide me to a simple example where i can write a simple 5 line program that can interact with a Database server to send and retrive a record or create a record. (i was told that this program is 5 lines).
web links, discussion forums, (on this ranch as well), or any other info please let me know. if this offtopic please move this thread to the relevant group. but in any case this is my email address and you can write to me. markstone23@yahoo.com

I think you'd probably have more success getting some good responses if you were to post this in the JDBC forum. Perhaps some friendly bartender could move it for you.
If not, however, I have one question for you. You say that you're supposed to connect to a database server, right? Is this a remote database that you need to get to (and if so, how), or is it a local database? If it's local, it's simple, but if the database is remote, you're going to have to come up with some way to communicate with it which might be a little more complicated.
Corey


SCJP Tipline, etc.
shivaji
Greenhorn

Joined: Jan 10, 2002
Posts: 7
Here is a sample that comes with Oracle . I suppose each database will have it's own quirks in connecting, but if you look up the relevant objects in JDBC, you should have an idea of what you need to do to connect to say MySQL database.
HTH


ps:
Disable the smiles when you post such code.
Thanks.
- satya
[ January 10, 2002: Message edited by: Madhav Lakkapragada ]
shivaji
Greenhorn

Joined: Jan 10, 2002
Posts: 7
OOPS!
The funny characters line should be like this
String url = "jdbc : oracle : oci8 : @";
without the spaces around the colons.
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
i guess it would be local only. because the scenario was equivalent to a cgi script that goes and interacts with database and sends the result back to the browser.
so i guess it would be local. right ? i don't know but that would be my guess. what do you think ?
basically one submits his query via a browser and the browser fires a script on the web server that runs another program that does the talking and etc with the database...

Originally posted by Corey McGlone:

I think you'd probably have more success getting some good responses if you were to post this in the JDBC forum. Perhaps some friendly bartender could move it for you.
If not, however, I have one question for you. You say that you're supposed to connect to a database server, right? Is this a remote database that you need to get to (and if so, how), or is it a local database? If it's local, it's simple, but if the database is remote, you're going to have to come up with some way to communicate with it which might be a little more complicated.
Corey
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
"shivaji"
your name doesn't agree with the javaranch guidelines. Please take a moment and re-register after reviewing the guidelines at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
mark:
I am moving this thread to the JDBC forum.
Please continue the discussion in that forum.
thanks.
- satya
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

here is one line of code that is fully functional in connecting to a database and printing out the results of the query to standard out.:

actually, I had to edit the code because the line of code was way too long and made the rest of the posts view off page so I took I removed most of it (just took a complete program and put it on one line!)
sample snippet:

you get the point though!
If you can cut out the class code,and exception handling and they only want you to write the code snippet to do this here is your 5 line answer:

Jamie
[ January 11, 2002: Message edited by: Jamie Robertson ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

better yet - 4 lines of code:
I made the 2nd line into 2 lines only so it doesn't throw the browser off as much. This code was compiled and run, so it works

Jamie
[ January 11, 2002: Message edited by: Jamie Robertson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: offtopic for cert but related to java basics