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



Home Answers Viewqa Java-Beginners ex. connect to Oracle
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


hendra
ex. connect to Oracle
1 Answer(s)      5 years and 8 months ago
Posted in : Java Beginners



Advertisement
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


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
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
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
Connect to the database
Connect to the database  how to connect to the database in the iphone
jdk6 and oracle 8i
jdk6 and oracle 8i  I connecte oracle 8i and jdk6 I notice that why can not connect
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
How to connect
How to connect  how to connect to a remote host using jsp? We need to update files to the database of the application on the local machine from the updated database on our webpage
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
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
Mysql connect
Mysql connect  i can have a mysql database file and mysql-connector-net .but i have not mysql database. how to connect vb.net thsis database.(C:\Documents and Settings\Admin\My Documents\VB.NET\Stock delna\STC.sql ). plz help me
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
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
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
servelet connectivity with oracle using procedure
servelet connectivity with oracle using procedure   kindly elaborate how servlet code connect to oracle br using procedure
Oracle - JDBC
Oracle fetch variables  i wanted to fetch variables from database using Oracle
connect with Database - SQL
connect with Database  Hi, when ever i m trying to connect with 10g...(WrapperDataSource.java:94) plz give me solution for this..   make sure your oracle... problem with java 2 v1.4 with oracle 10g. But it worked well with the same code
oracle 18/04/2013
oracle 18/04/2013   Why it is called as structured query language
Oracle - SQL
Oracle  Oracle Begginers , if Downloadable Notes are there Please mention the site
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
Advertisements
 

 

 

DMCA.com