Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC jdbc connections
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


V.A.G.Raju
jdbc connections
1 Answer(s)      3 years and 9 months ago
Posted in : JDBC


How can I coonect with oracle9i with java program using both thin driver and sun driver. plz send sample code for both the drivers


Advertisement
View Answers

January 21, 2011 at 11:00 AM


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


Related Tutorials/Questions & Answers:
jdbc connections
jdbc connections  How can I coonect with oracle9i with java program... oracle.sql.*; 2) Load and Register the JDBC driver: DriverManager.registerDriver... oci driver,you have to use: Connection conn = DriverManager.getConnection("jdbc
Connections with MicroSoft SQL - JDBC
Connections with MicroSoft SQL  How to Connect Java and MS SQL?? Actually i used below code i got SQLException and class not found... import...; Statement st = null; ResultSet rs = null; String url = "jdbc
Advertisements
how to implements jdbc connections using awt
how to implements jdbc connections using awt  sir, My name... valuable information about how to implements jdbc connections in awt.please give me sample example awt with jdbc. Thanking you sir.  
how to implements jdbc connections using awt?
how to implements jdbc connections using awt?   My name is Aditya... information about how to implements jdbc connections in awt.please give me sample example awt with jdbc.   We are proving you a simple application
closing connections in finally block
closing connections in finally block  Hi, What will happen if I close connection before closing the resultset in the finally clock? e.g. finally... { ... conn.close(); rs.Close(); } If i do as above ... what will happen
httpd.conf max connections
connections? Thanks   Hi, You can add following configuration in httpd.conf file to increase the number of connections to be handled by apache server
DOubt in Mysql connections
DOubt in Mysql connections  i have some problem regarding data base connections, i have created a hostname, username and password in filezilla server but after i give those names also it is showing error like this: mysql
JDBC Versions
JDBC Versions       1). The JDBC 1.0 API. 2). The JDBC 1.2 API. 3). The JDBC 2.0 Optional Package API. 4). The JDBC 2.1 core API
maximum limit of database connections have been reached.
maximum limit of database connections have been reached.  How do I check in my code whether a maximum limit of database connections have been reached
maximum limit of database connections have been reached.
maximum limit of database connections have been reached.  How do I check in my code whether a maximum limit of database connections have been reached
Interact with connection pools to obtain and release connections
and release connections Prev Chapter 4. Demonstrate understanding... to obtain and release connections Connection handles... application Data Source</description> <res-ref-name>jdbc
JDBC access database
JDBC access database       JDBC is a Java Database Connectivity. The JDBC Connectivity provides API classes and interfaces for connecting the front end in Java application with database connections
how to connection jsp to oracle database connections in netbeans ide
how to connection jsp to oracle database connections in netbeans ide  how to connect jsp to oracle database connections in netbeans ide?pls provide screenshots if possible
how to connection jsp to oracle database connections in netbeans ide
how to connection jsp to oracle database connections in netbeans ide  how to connect jsp to oracle database connections in netbeans ide?pls provide screenshots if possible
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jdbc
jdbc  display the records using index in jdbc
JDBC
JDBC  why we use batch in jdbc
jdbc - JDBC
jdbc  Hi.. i am running the servlet program with jdbc connections in this porgram i used two 'esultset' objects.. in this wat ever coding is available in the first resultset is executed like updating and retrieiving
JDBC
JDBC  How to add set of queries in a single query in JDBC
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
jdbc
jdbc  please tell me sir.i dont know JDBC connection and how to create table in database
jdbc
jdbc define batch updates  define batch updates?exp   JDBC... links: http://www.roseindia.net/jdbc/Jdbc-batch-update.shtml http://www.roseindia.net/tutorial/java/jdbc/batchupdateresultsetexample.html
jdbc
jdbc  Write a web based student registration application where the students can register online with their enrollment no. You are required to use JSP, Servelet and JDBC
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
 

 

 

DMCA.com