473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to connect to an oracle database from a java source

Please give me some sample codes to connect oracle database from a java program.
Nov 16 '05 #1
1 13528
Niheel
2,460 Expert Mod 2GB
Your are going to have to use an Oracle JDBC driver to connect to the database.

Below is the java code to use in conjunction with the driver and the oracle database.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Connection connection = null;
  3.     try {
  4.         // Load the JDBC driver
  5.         String driverName = "oracle.jdbc.driver.OracleDriver";
  6.         Class.forName(driverName);
  7.  
  8.         // Create a connection to the database
  9.         String serverName = [color=#0066ff]"127.0.0.1"[/color];
  10.         String portNumber = [color=#0066ff]"1521"[/color];
  11.         String sid = [color=#0066ff]"mydatabase"[/color];
  12.         String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
  13.         String username = [color=#0066ff]"username"[/color];
  14.         String password = [color=#0066ff]"password"[/color];
  15.         connection = DriverManager.getConnection(url, username, password);
  16.     } catch (ClassNotFoundException e) {
  17.         // Could not find the database driver
  18.     } catch (SQLException e) {
  19.         // Could not connect to the database
  20.     }
  21.  
For more information please read this FAQ carefully.
http://www.orafaq.com/faqjdbc.htm#JDBC

Hope that helps. Let us know how it went.
Nov 16 '05 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
Hello all, I have been trying to use the OCI driver to connect to Oracle 9i, but have been getting the following error: java.sql.SQLException: Closed Connection at...
1
by: CM | last post by:
Hi, when i want connect me in my BD with a JSP (with this simple code), this exception is throw. Thank's for ur help Mathieu CODE of my JSP ---------------------
1
by: C.O.Jones | last post by:
Using Oracle 8.1.7 Personal edition on Windows XP. I was experimenting with the DBA tools. I first of all tried to adjust the memory used by my database. Then I attempted to shutdown and...
2
by: Suresh Tri | last post by:
Hi all, I am interested in extracting the class or jar files which are stored as java stored procedures in Oracle. But I want to know if these are stored as references to external files in...
125
by: Rhino | last post by:
One of my friends, Scott, is a consultant who doesn't currently have newsgroup access so I am asking these questions for him. I'll be telling him how to monitor the answers via Google Newsgroup...
5
by: jrefactors | last post by:
My machine is Windows XP with Oracle 9.2 Home; IIS and Oracle are in the same box. I have tried both Oracle OLEDB Provider and Microsoft ODBC For Oracle, but both not working. For Microsoft...
6
by: ´ď´ď | last post by:
How to connect asp.net with Oracle Database? Where and How to? Thanks very much.
2
by: Vinod Sadanandan | last post by:
All, Below listed are the new features in Oracle 11g ,please join me in this discussion to generate a testcase and analyze each of the listed features . Precompilers:...
5
by: raghu4uon | last post by:
hi Can anyone give source code to connect oracle 8 database to my java project????? i'm using jdk1.5, tomcat 5.5.9 web server, oracle 8..... i have created the tables but i dont know how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.