• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
yomi Balogun
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Swaminathan Balasubramani
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A google search on 'JDBC tutorial' would be most instructive.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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 ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic