• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

offtopic for cert but related to java basics

 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OOPS!
The funny characters line should be like this
String url = "jdbc : oracle : oci8 : @";
without the spaces around the colons.
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mark:
I am moving this thread to the JDBC forum.
Please continue the discussion in that forum.
thanks.
- satya
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Everybody's invited. Even this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic