jdbc connections

jdbc connections

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

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
ModuleNotFoundError: No module named 'connections'
ModuleNotFoundError: No module named 'connections'  Hi, My Python... 'connections' How to remove the ModuleNotFoundError: No module named 'connections' error? Thanks   Hi, In your python environment
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
ModuleNotFoundError: No module named 'mypy-boto3-codestar-connections'
ModuleNotFoundError: No module named 'mypy-boto3-codestar-connections' ...: ModuleNotFoundError: No module named 'mypy-boto3-codestar-connections' How to remove the ModuleNotFoundError: No module named 'mypy-boto3-codestar-connections' error
ModuleNotFoundError: No module named 'nw-connections'
ModuleNotFoundError: No module named 'nw-connections'  Hi, My... named 'nw-connections' How to remove the ModuleNotFoundError: No module named 'nw-connections' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-connections'
ModuleNotFoundError: No module named 'django-connections'  Hi, My... named 'django-connections' How to remove the ModuleNotFoundError: No module named 'django-connections' error? Thanks   Hi, In your
JDBC Versions
JDBC Versions       1). The JDBC 1.0 API. 2). The JDBC 1.2 API.ADS_TO_REPLACE_1 3). The JDBC 2.0 Optional Package API. 4). The 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
ModuleNotFoundError: No module named 'django-user-connections'
ModuleNotFoundError: No module named 'django-user-connections'  Hi...: No module named 'django-user-connections' How to remove the ModuleNotFoundError: No module named 'django-user-connections' error? Thanks   
ModuleNotFoundError: No module named 'django-user-connections'
ModuleNotFoundError: No module named 'django-user-connections'  Hi...: No module named 'django-user-connections' How to remove the ModuleNotFoundError: No module named 'django-user-connections' error? Thanks   
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...-name>jdbc/TitanDS</res-ref-name> <res-type>javax.sql.DataSource<
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  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 - 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  please tell me sir.i dont know JDBC connection and how to create table in database
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
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  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
JDBC - JDBC
JDBC - limitations of jdbc  What are the limitations of JDBC
jdbc - JDBC
Why JDBC   JDBC used for what
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
jdbc
how can we set transaction level through jdbc api  how can we set transaction level through jdbc api   Use Connection.setTransactionIsolation(int) to set the desired tansaction level, which takes one of the 5 arguments
jdbc
how can we call stored procedure using jdbc  how can we call stored procedure using jdbc   Call a Stored Procedure using...(); For more information, visit the following link: JDBC call Stored Procedure
jdbc - JDBC
Java JDBC application  Database Application in Java JDBC
JDBC - JDBC
JDBC Select Count Example   Need an example of count in JDBC
JDBC - JDBC
JDBC -statement types in jdbc  statement types in jdbc
jdbc - JDBC
Loading JDBC driver at runtime  How to load JDBC Driver at runtime
jdbc
jdbc  hey sir i just wanna have some ppt on jdbc coz have my exams next week and i have not attended any classes coz of job... I m studyng frm niit
jdbc
jdbc  I can't run my jdbc program because it has error in this line: public static void main(String[] args) the error is:illegal static declaration in inner class would you please let me whats the problem? regards
jdbc
using jdbc connection   import java.sql.*; public class CreateTable... = DriverManager.getConnection("jdbc:odbc:student"); Class.forName
jdbc
jdbc  i had written jdbc connection in method and i need to get connection in another class?   import java.sql.*; class... driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/test
jdbc
(); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost... information, visit the following link: JDBC Tutorials

Ads