Java vs Oracle Connectivity

Java vs Oracle Connectivity

View Answers

September 21, 2009 at 1:10 PM

Hi Friend,

Use Oracle with Java

Follow these steps:

1) Import the following packages in your java file:***********

import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;

2) Load and Register the JDBC driver:***********

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

or you can use Class.forName("oracle.jdbc.driver.OracleDriver");

3) Connect to database:***********

a) If you are using oracle oci driver,you have to use:

Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:
@oracle.world", "root", "root");

where oracle.world is the TNSNAMES entry and root is the username and password.

b) If you are using oracle thin driver,you have to use:

Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:roseindia",
"root", "root");

where localhost is the host,3306 is the port, roseindia is the database and root is the username and password.

4) Querying the database:**********

a)create statement:

Statement st = conn.createStatement();

b)write query and execute the query:

ResultSet rs = st.executeQuery("SELECT * from student");

5) Close the statement,resultset and connection:**********

rs.close();
st.close();
conn.close();

Try the following code:

import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;

public class OracleExample {
public static void main (String[] args) {
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost:3306:Oracle", "rose", "rose");
Statement st = conn.createStatement();
ResultSet rs = sql_stmt.executeQuery("SELECT * from student");
String str = "";
while (rs.next())
{
System.out.println(rset.getInt(1)+" "+ rs.getString(2)+" "+ rset.getFloat(3)+"\n";
}
rs.close();
st.close();
conn.close();
}
catch(Exception e){}
}
}

Thanks









Related Tutorials/Questions & Answers:
Java vs Oracle Connectivity - JDBC
Java vs Oracle Connectivity  Write a java program to establish connection with oracle database?  Hi Friend, Use Oracle with Java Follow these steps: 1) Import the following packages in your java file
oracle vs sql
oracle vs sql  what is the difference between oracle and sql
Advertisements
oracle connectivity
oracle connectivity  con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr"); i have error on above line when i tried...=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr
oracle connectivity problem with netbeans
oracle connectivity problem with netbeans  sir I am using oracle.... for this after adding new driver(ojdbc6.jar) in services tab I got connectivity with oracle... of simple connectivity with oracle in this I am giving driver details
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please suggest me if there is some different way to connect swing application to oracle
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two... am using the oracle. please help. thankyou sir
Oracle Database connectivity probem
Oracle Database connectivity probem  hi Below is the code of oracle database connectivity, when i compile it, it will show the error... also set the environment variable like that .;E:\oracle\ora81\jdbc\lib
servelet connectivity with oracle using procedure
servelet connectivity with oracle using procedure   kindly elaborate how servlet code connect to oracle br using procedure
JSP-Oracle connectivity
JSP-Oracle connectivity  I have created a "dynamic web project" mainly with jsp files in eclipse and now, want to connect with oracle 10g, so how can I proceed for the database connection
Database Connectivity Withe Oracle
Database Connectivity Withe Oracle  Develop a program to perform the database driven operation like insert, Delete, Update and select. To perform the above operations create one table named Employee. Field Name Field Type EmpId
jsp page connectivity with oracle - SQL
jsp page connectivity with oracle  I am unable to database connectivity jsp with oracle. Please send the code for solving problem. thanks  Hi Friend, 1)Import the packages: 2)Load the oracle driver
how to solve this problem for oracle connectivity
how to solve this problem for oracle connectivity  Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap ter could not establish the connection
OCI Connectivity For Oracle Plz Solve This Error
OCI Connectivity For Oracle Plz Solve This Error  import java.io.*; import java.sql.*; import java.lang.*; import oracle.jdbc.OracleDriver; public..."); con=DriverManager.getConnection("jdbc:oracle:thin
OCI Connectivity For Oracle Plz Solve This Error
OCI Connectivity For Oracle Plz Solve This Error  import java.io.*; import java.sql.*; import java.lang.*; import oracle.jdbc.OracleDriver; public..."); con=DriverManager.getConnection("jdbc:oracle:thin
java vs vb
java vs vb  history of java and advanced products as well as vb? compared with java and vb? finalize list out the table of java and vb products? viewers i want more soon
java vs .net - Java Beginners
java vs .net  which language is powerful now java or .net
Java connectivity with MySQL
Java connectivity with MySQL  Java connectivity with MySQL
java connectivity
java connectivity  hi........ Can u help me to do connectivity between java and weka??????? weka is a data mining tool which allows to do prediction, classification etc.... i want to do connectivity between weka and java can u
Order of list in java Vs Haskell.
Order of list in java Vs Haskell.  How to order of [1,2,3] to [1,2,3,2,1]in java
java vs vb
history of java  history of java and advanced products as well as vb? compared with java and vb? finalize list out the table of java and vb products? viewers i want more soon
java-oracle
java-oracle  hi friends, I wanted to upload a image from jsp page to oracle database.i am not getting how to do it... Please help me if you can....... please give me detail code
java connectivity
java connectivity  i am trying to add dyanamic rows in the jsp page, when i add the new row the dropdown control value is not coming from database..please help me to overcome this problem
sql connectivity through java
sql connectivity through java  i want an example for java db through sql connection. Thanks in advance
Encapsulation VS Abstraction - Java Beginners
Encapsulation VS Abstraction  Real Time sample code for Encapsulation and Abstraction. where to use abstract and where to use specifies like public...(); } Abstraction-The process of abstraction in Java is used to hide certain details
arraylist vs vector - Java Beginners
arraylist vs vector  hi, i want to know what is the difference between arraylist and vector in case of performance. in what cases we should go for arraylist and in what case we should go for vector. is there any   array
'String' vs 'StringBuffer' - Java Beginners
'String' vs 'StringBuffer'  What should i use String or StringBuffer?  Hi, First you need to rectify the question. Because StringBuffers append the data, and Strings concatenate the data. Since Strings are immutable
Servlet vs Class - Java Beginners
Servlet vs Class  I have worked on lot of projects and written number of classes myself. I have never started a project myself. Now I am assigned a task of starting a project. Could you please guide me if to start a project using
JDBC, Java Database Connectivity
have in our site roseindia.net. Our website is very famous for JDBC and Java tutorials. Java Database Connectivity or JDBC for short is Java bases API... Connectivity or JDBC for short is a standard API in Java for accessing
Oracle - Java Beginners
Oracle   Hi sir, I installed oracle but the error occur on The java Runtime Environment was not found, at bin\jrew.exe. Hence the Oracle Universal Installer can not be run JRE version 1.1.7 Are the Java and Oracle related
JAVA BEAN WITH ORACLE FORMS
JAVA BEAN WITH ORACLE FORMS  Hi..I am doing my final year Project.. I need the ste-by-step procedure to integrate a bean with oracle forms? Please help me
java to oracle code - JDBC
java to oracle code  please suggest m calculate the database performance between scaled images and unscaled images in the database
java with Oracle Database
java with Oracle Database  Hello I have been encountering a problem regarding creating a table with Oracle.When i am creating new table in the Database using Oracle , it is giving error saying an errror occured incursive sql
Java to SQL Server Connectivity
Java to SQL Server Connectivity  Hi, heres my code private void... with sql server connectivity at the background to save the data. Now, after... the connectivity wrong. Kindly help me resolve this issue ASAP. Thank you
java and oracle - JSP-Servlet
java and oracle  I am developing a small project where I need to upload the resume of the employee and store it into database and retrieve the same... data types in oracle database. And I need to write the code in servlets
Java Connection to Oracle database
Java Connection to Oracle database  HI I am ubable to connnect jdbc to Oracle database.i had gone to control panel >>Administrative tool>>>Data source,in that forDNS name i typed Oracle and in TNS i culdn't
Reference type Vs Object type. - Java Beginners
Reference type Vs Object type.  Can anyone explain the exact.... They never contain the object. C++ object variables may be either, but Java supports only object references. For Example : Book bookvar = new Book("Java
connectivity
connectivity  sir i have created a web page for login form and i have also created the related data base in both ms access and oracle 10g now how to store those values in form to databases can u plz hlp me
database connectivity in java - JDBC
database connectivity in java  import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; class Project implements ActionListener { JFrame f; JPanel p1,p2,p3; JTabbedPane
Probability Vs. Number of people table - Java Beginners
Probability Vs. Number of people table  The probability that at least two people in the group of 5 people will have the same birthday is: 1... loops we need to create a program that will show the table: probability vs. number
Java database connectivity
Java database connectivity  Hi sir I need a code to create an application where user enter name in text box and that should be stored in database. Plz help me out its very urgent.   import java.sql.*; import java.awt.
java connecting to oracle db
java connecting to oracle db  PLZ SAY ME HOW TO INSERT THE VALUES INTO ORACLE THIS IS THE CODE: import java.io.*; import java.sql.*; import..."); Connection con=DriverManager.getConnection("jdbc:oracle:thin
connectivity
connectivity  how to connect java with database
oracle
oracle   sir now am doing one project , my frond end is vb and backend is oracle. so 1> how can i store the image in my field 2> how can i back up the table into .txt file
DataBase connectivity in java with Microsoft sql server2000 - JDBC
DataBase connectivity in java with Microsoft sql server2000  How i can achieve database connectivity with Microsoft sql server2000 in my java source code
java servlet connectivity problem with access
java servlet connectivity problem with access  Import java.sql javax.servlet //all packages entered try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc
java connecting to oracle db - JDBC
java connecting to oracle db  how to connect oracle data base with java application?  Hi Friend, Follow these steps: 1) Import the following packages in your java file:*********** import java.sql.*; import
java and oracle - JSP-Servlet
java and oracle  hai i am doing a project in which i have stored some data (think as 50 records) in database. Now i want to retrive the data from the database(20 records at each time but should be different for each time
Java Barcode Program with Oracle database
Java Barcode Program with Oracle database  Hi Everyone, I need help... no and serial no of the item being scanned to Oracle 10g database. I dont have any idea abt this...Please can anyone give me some idea. Do I need to buy Java
ex. connect to Oracle - Java Beginners
ex. connect to Oracle  dear sir, I want to ask how to connect java to oracle, please give me a details tutorial with example code how to connect to oracle. what software i must to use? thank's   Hi
java oracle connection problem - SQL
java oracle connection problem  I have successfully made connection with the oracle10g database that i am using and also able to put in data using JSP. But the codes that i have tried for fetching the data are not working even

Ads