Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

ex. connect to Oracle

Ads

 
 

Share on Google+Share on Google+

hendra
ex. connect to Oracle
1 Answer(s)      8 years ago
Posted in : Java Beginners
Ads
View Answers

April 1, 2009 at 9:29 AM


Hi friend,

Code to help in solving the problem :

import java.sql.*;
import java.io.*;

public class JdbcConnection{

Connection con = null;

String serverName = "localhost";
String portNumber = "1521";
String db = "XE";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + db;
String driver = "oracle.jdbc.driver.OracleDriver";
String user = "";
String pass = "";

public Connection getConnection(){
try{
Class.forName(driver);
con = DriverManager.getConnection(url, user, pass);
}
catch (ClassNotFoundException e){
System.err.println("Could not load JDBC driver");
System.out.println("Exception: " + e);
e.printStackTrace();
}
catch(SQLException ex){
System.err.println("SQLException information");
while(ex!=null) {
System.err.println ("Error msg: " + ex.getMessage());
System.err.println ("SQLSTATE: " + ex.getSQLState());
System.err.println ("Error code: " + ex.getErrorCode());
ex.printStackTrace();
ex = ex.getNextException(); // For drivers that support chained exceptions
}
}
return con;
}

public void closeConnection(){
try{
con.close();
}
catch(SQLException ex){
System.err.println("SQLException information");
while(ex!=null) {
System.err.println ("Error msg: " + ex.getMessage());
System.err.println ("SQLSTATE: " + ex.getSQLState());
System.err.println ("Error code: " + ex.getErrorCode());
ex.printStackTrace();
ex = ex.getNextException(); // For drivers that support chained exceptions
}
}
}

}

Thanks

Ads









Related Tutorials/Questions & Answers:
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
connect netbeans with oracle
connect netbeans with oracle  how to connect netbeans with oracle   Hi Friend, Please visit the following link: http://www.roseindia.net/jsf/visual-jsf.shtml Here you will find the steps to connect netbeans
Advertisements
Connect GWT application with Oracle
Connect GWT application with Oracle  Can anyone tell me how to connect gwt with oracle database...??? I tried but, I failed every time. If possible please rply with a sample code in while database is connected in gwt application
JDBC Connection code to connect servlet with oracle.
JDBC Connection code to connect servlet with oracle.  JDBC Connection code to connect servlet with oracle
How to connect to the database to my application if my database is made up in oracle
How to connect to the database to my application if my database is made up in oracle   How to connect to the database to my application if my database is made up in oracle
How to connect to database to my application if the database is made up in oracle
How to connect to database to my application if the database is made up in oracle  How to connect to database to my application if the database is made up in oracle   Hi Friend, Follow these steps: 1) Import
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data.... If I use it also, unable to connect to backend oracle database. Let me... properties file JNDI_NAME=java:com/env/Oracle/jndi db.login= db.password
java script unable to connect to oracle database and insert data
java script unable to connect to oracle database and insert data  ... is to insert data from jsp to oracle database 8, so i create a table in oracle... jsp coding in rose india for sql and i changed the drivers for oracle.. when i try
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
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
jdk6 and oracle 8i
jdk6 and oracle 8i  I connecte oracle 8i and jdk6 I notice that why can not connect
wt are the futures in jdk 1.5 with clear ex
wt are the futures in jdk 1.5 with clear ex  plese send me the correce ex
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
oracle - JDBC
oracle  HI i am using ORACLE 10g. How to i find "TNSNAMES.ORA" file in my system after installation of ORACLE 10g succussfully. please send... that depends on the actual network implementation used. Oracle recommends that SDU
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
Connect to the database
Connect to the database  how to connect to the database in the iphone
servelet connectivity with oracle using procedure
servelet connectivity with oracle using procedure   kindly elaborate how servlet code connect to oracle br using procedure
android connection to database oracle 10g
android connection to database oracle 10g  Hello, How i can connect my android application to my oracle 10g database
oracle - SQL
) from employee)); In Oracle, you can use the following query: select max(salary) from employee where level=3 connect by prior salary>salary; Thanks
Oracle - JDBC
Oracle fetch variables  i wanted to fetch variables from database using Oracle
Oracle - SQL
Oracle  Oracle Begginers , if Downloadable Notes are there Please mention the site
oracle 18/04/2013
oracle 18/04/2013   Why it is called as structured query language
Oracle BLOB
Oracle BLOB  Can anyone send me the code for inserting an image or audio into the oracle database using BLOB datatype. Plz...it's useful for my project
oracle connectivity problem with netbeans
oracle connectivity problem with netbeans  sir I am using oracle window version +net bean6.8. jam trying to connect net bean to oracle. for this after adding new driver(ojdbc6.jar) in services tab I got connectivity with oracle
oracle conditions
oracle conditions  can you briefly explain about the "EXISTS" condition in SQL with examples
write excel file into the oracle database
write excel file into the oracle database  dear sir, i need the jsp code that reads the excel file and stores it into the oracle database table..and also i need the code to connect oracle database? thank u in advance
oracle - JDBC
oracle  sir iam hari iam doing the project using oracle with jdbc in xp when iam inserting the data it is giving error like ora-01034:oracle not available sir plz.......give me the solution it is urgent sir thanku
oracle problem
oracle problem  Hi I have installed oracleXE on my system and for reasons i've uninstalled them and am not able to stop oracle xe services and i could'nt reinstall it. I couldnt reinstall my os for this as it is in my office
Oracle - SQL
Oracle  I have one .dmp file. I want to import this file into oracle 9i and oracle 10g. wat is procedure and stepts. thanks u  Open... D:\oracle\ora90\BIN\imp type this command if your are using oracle 9i
oracle - JDBC
to store these two fields into oracle database for that i have given one jsp page... it is giving error like java.sql.SQLException:[MICROSOFT][ODBC Driver for oracle][oracle