Java Jdbc

Java Jdbc

sir i want to databse(oracle 10g)connectivity through java through program

View Answers

January 5, 2011 at 1:42 PM

Hi Friend,

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

Ads









Related Tutorials/Questions & Answers:
Java JDBC
Java JDBC  How to make pagination using JDBC
Java JDBC ODBC
Java JDBC ODBC  What is the difference between JDBC and ODBC
Advertisements
Java Jdbc
Java Jdbc  sir i want to databse(oracle 10g)connectivity through java through program   Hi Friend, Follow these steps: 1) Import the following packages in your java file: import java.sql.*; import
JDBC, JAVA
JDBC, JAVA  I want to develop a s/w that will work on a LAN, so is there any need for a server, bcoz I am using database to store information, and these information will be on LAN
java - JDBC
Java home dir  What is the Home Directory for Java
java - JDBC
java  How to generate a report in java like we do in vb
Java - JDBC
Java  How to Connect the java with oracle by using type2 driver? can you tell me the steps
java - JDBC
as a Boolean class instance. All of the primitive wrapper classes in Java... to : http://www.roseindia.net/java/wrapper-class/ Thanks
java - JDBC
to : http://www.roseindia.net/java/exceptions/ Thanks
Java JSP - JDBC
Java JSP  JDBC connectivity in JSP?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml Hope that it will be helpful for you. Thanks
java,jdbc,netbeans
java,jdbc,netbeans  can you tell me the program which read multiple dbf files and then insert those dbf files data in msaccess automatically
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
jdbc
links: http://www.roseindia.net/jdbc/Jdbc-batch-update.shtml http://www.roseindia.net/tutorial/java/jdbc/batchupdateresultsetexample.html...jdbc define batch updates  define batch updates?exp   JDBC
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database... = "jdbc:mysql://localhost:3306/"; String db = "register"...://www.roseindia.net/jdbc
JDBC
between java and mysql using JDBC and saves the data into the database. import...JDBC save a data in the database  I need a code to save a data... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
the connection between java and mysql using JDBC and saves the data into the database...JDBC code to save a data in the database  I need a code to save...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jdbc
of ms-access using java application i want to perform both operations of ms-access using jdbc connection   import java.sql.*; public class CreateTable... = DriverManager.getConnection("jdbc:odbc:student"); Class.forName
JDBC
JDBC  How to add set of queries in a single query in JDBC
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java... in GUI window using jdbc-odbc separate program i had written. Now what i want...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java... in GUI window using jdbc-odbc separate program i had written. Now what i want...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
JDBC
retrieve the value from database into dropdown list using JDBC SQL 2005  How to retrieve the value from database into dropdown list using JDBC &...").newInstance(); String connectionURL = "jdbc:mysql://localhost:3306/test";; Connection
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
excel file using JDBC java.?
excel file using JDBC java.?  hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a excel file and then appends the same... used JDBC ODBC to read from excel file. i am not able to append it using

Ads