Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how do i connect java to my oracle server i,m just beginning on jdbc

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm new to the jdbc but i need help on the detail steps to help a novice just reading on jdbc but with an above average knowledge in java and oracle to make java through jdbc connect with my oracle server.thanks for the anticipated response.
yomi
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yomi,

Hope the follwing code helps u

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
// Establishing Connection with database
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
dbcon=DriverManager.getConnection("jdbc racle:thin:system name/IP address:1521(port ID):SID","username","password");
System.out.println("Connection Established");
}

catch(ClassNotFoundException e)
{
System.out.println("Database Driver not found");
System.out.println(e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}

To find the Port ID,Database Name and other details see for TNSNAMES.ORA in Oracle Home directory.

For more information,check this outClick
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A google search on 'JDBC tutorial' would be most instructive.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I copied this technique from somewhere ... any expert opinions on whether it's good or bad?

You can guess the register method is in a base class, the rest is is in an Oracle subclass. I think the class for register and the syntax for getConnection are the only db specific things, all my other "wrapper" code is in the base class.

BTW: Where you see : o like ": oracle" I added the space after teh colon so it's not a Graemlin.
[ April 12, 2005: Message edited by: Stan James ]
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stan,

My general comment (not expert ) is only one that DB specific code and common code is separated. One main advantage I see in this code is that reusability of code. I can funrther extend the base class for another type of DB so I would be require to write only DB specific code.
Hope we can figure out more

Shailesh
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have Oracle, DB2, SQL2000 and ODBC versions of this so far. I have a little app that will run a query against any two databases and compare the results, and a little config file with the db type, db name, uid and password. It can connect to anything on the project for sure.
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic