connectivity step

Ads
 

connectivity step

sir.pls give me step one by one for connect the java program to oracle.

View Answers

March 26, 2012 at 12:19 PM

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){}
}
}

Ads









Related Tutorials/Questions & Answers:
connectivity step
connectivity step  sir.pls give me step one by one for connect the java program to oracle.   Follow these steps: 1) Import the following packages in your java file:*** import java.sql.*; import oracle.jdbc.driver.
ModuleNotFoundError: No module named 'step-by-step-tg-bot'
ModuleNotFoundError: No module named 'step-by-step-tg-bot'  Hi, My... named 'step-by-step-tg-bot' How to remove the ModuleNotFoundError: No module named 'step-by-step-tg-bot' error? Thanks   Hi
Advertisements
database connectivity
database connectivity  how to create database connectivity between HTML and sql server2005
Java connectivity with MySQL
Java connectivity with MySQL  Java connectivity with MySQL
Hibernate example step by step in Eclipse with MySQL
Hibernate example step by step in Eclipse with MySQL  Hi, I am total... and looking for any good Hibernate example for learning step by step in Eclipse... to write Hibernate program using Eclipse Step by Step. This video tutorial
connectivity with php
connectivity with php  i have make one html form and doing connectivity with php database but when i click on submit button on html form display all coding in php form about connectivity instead of adding data, i used in html
I want to learn hibernate step-by-step.
I want to learn hibernate step-by-step.  Hello, I am very new... to start from start and learn it step by step. Can you please help me.. I would... Hibernate step-by-step, just go through the following links that are provided here
ModuleNotFoundError: No module named 'step'
ModuleNotFoundError: No module named 'step'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'step' How to remove the ModuleNotFoundError: No module named 'step' error
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
connectivity problem
connectivity problem  i am facing error in Class.for name statement... connectivity still i am facing this error* ================================oracle connectivity program============================ import java.sql.*; import
connectivity with access
connectivity with access  how to connect with data base with access sheet. in my application form there is two JTextArea and Two JComboBox.   Is this Access database or excel sheet. Do you want to display the values
JDBC CONNECTIVITY
file in environment variable.   Java Mysql connectivity Other JDBC
connectivity with mysql
connectivity with mysql  if this code of roseindia doesnt work,then what to do..cant connect with my sql http://www.roseindia.net/tutorial/php/phpdatabase/Check-PHP-MySQL-Connectivity.html   Please visit the following
connectivity
connectivity
connectivity
JDBC CONNECTIVITY
connectivity Other JDBC Tutorials
ModuleNotFoundError: No module named 'connectivity'
ModuleNotFoundError: No module named 'connectivity'  Hi, My Python... 'connectivity' How to remove the ModuleNotFoundError: No module named 'connectivity' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cassandra-step'
ModuleNotFoundError: No module named 'cassandra-step'  Hi, My... named 'cassandra-step' How to remove the ModuleNotFoundError: No module named 'cassandra-step' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cf-step'
ModuleNotFoundError: No module named 'cf-step'  Hi, My Python...-step' How to remove the ModuleNotFoundError: No module named 'cf-step... to install padas library. You can install cf-step python with following command
ModuleNotFoundError: No module named 'custom-step'
ModuleNotFoundError: No module named 'custom-step'  Hi, My Python... 'custom-step' How to remove the ModuleNotFoundError: No module named 'custom-step' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'forcefield-step'
ModuleNotFoundError: No module named 'forcefield-step'  Hi, My... named 'forcefield-step' How to remove the ModuleNotFoundError: No module named 'forcefield-step' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lammps-step'
ModuleNotFoundError: No module named 'lammps-step'  Hi, My Python... 'lammps-step' How to remove the ModuleNotFoundError: No module named 'lammps-step' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'lammps-step'
ModuleNotFoundError: No module named 'lammps-step'  Hi, My Python... 'lammps-step' How to remove the ModuleNotFoundError: No module named 'lammps-step' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'loop-step'
ModuleNotFoundError: No module named 'loop-step'  Hi, My Python... 'loop-step' How to remove the ModuleNotFoundError: No module named 'loop-step' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'mopac-step'
ModuleNotFoundError: No module named 'mopac-step'  Hi, My Python... 'mopac-step' How to remove the ModuleNotFoundError: No module named 'mopac-step' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'packmol-step'
ModuleNotFoundError: No module named 'packmol-step'  Hi, My Python... 'packmol-step' How to remove the ModuleNotFoundError: No module named 'packmol-step' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pi_step'
ModuleNotFoundError: No module named 'pi_step'  Hi, My Python..._step' How to remove the ModuleNotFoundError: No module named 'pi_step... to install padas library. You can install pi_step python with following command
ModuleNotFoundError: No module named 'slash-step'
ModuleNotFoundError: No module named 'slash-step'  Hi, My Python... 'slash-step' How to remove the ModuleNotFoundError: No module named 'slash-step' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'step-template'
ModuleNotFoundError: No module named 'step-template'  Hi, My... 'step-template' How to remove the ModuleNotFoundError: No module named 'step-template' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'table-step'
ModuleNotFoundError: No module named 'table-step'  Hi, My Python... 'table-step' How to remove the ModuleNotFoundError: No module named 'table-step' error? Thanks   Hi, In your python environment you

Ads