How to connect java with oracle

can any body show me the code of how to connect java with oracle database.
thank you

To configure Oracle JDBC:
1. Add Oracle JDBC JAR file or to classpath.
2. Load and register the JDBC driver.
3. Obtain a connection:
String url="jdbc:oracle:thin:@<host>:1521:<database>
Connection con = DriverManager.getConnection(url,
"myLogin", "myPassword");
4. Create a SQL statement.
Statement stmt = con.createStatement();
5. Obtain a result set.
ResultSet rs = stmt.executeQuery(
"SELECT ...");

Similar Messages

  • How to connect Java to oracle Database Express Edition?

    Anyone can help me?

    I suggest you to read this article:

  • Unable to connect JAVA with Oracle

    I have jdk1.6 and oracle installed on my machine but unable to connect java with database
    have classes12.jar and ojdbc14.jar
    my environmental variables in respect to this are :
    JAVA_HOME= C:\Java\jdk1.6.0_04
    C:\Program Files\Oracle\jre\1.3.1\bin;
    C:\Program Files\Oracle\jre\1.1.8\bin
    The code is
    import java.sql.*; public class dat1 {               public static void main(String[] args)throws SQLException,ClassNotFoundException {         try     {     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");     Class.forName("");     } catch (ClassNotFoundException e) { System.out.println("unable to load driver"); return; }     } }
    the error message is
    Error in thread "main" java.lang.NoClassDefFoundError
    Please Help Me
    Thanks For Reading
    Thanks a lot in Advance For your ANSWERS

    maybe if you asked nicely instead of ordering people around we might tell you.
    As it is all you're going to hear is that you don't need both those jars, as they contain different versions of the same driver.
    I'm not going to tell you which you need, as you should have the documentation to tell you that. But then you also should have the documentation to tell you how to set your classpath properly and you failed to read that too.

  • How to connect java with database without any dsn.

    is there any way to connect java with database with out creating any we do in ado in vb by providing provider.

    Sure use a type 4 driver. No DSN.

  • How to connect Java with Acces (DSN Less)

    Hi, I'm try to connect an Access DataBase in Java with an example. I find it in this forum, but don't work...
    I've my database in the folder Data, and its name is BaseDat.mdb...
    I'm working in NetBeans 5.5, and the DataBase is in the Folder: "C:/Documents and Settings/MetalTux/POOL/src/Data/BaseDat.MDB"...
    This way, its work, but It's another way to use this... without the "C:/Documents and Settings/MetalTux/POOL/src/"????
    Please help me... and sorry my english...

    I have this in my code:
    Connection conec = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Documents and Settings/MetalTux/POOL/src/Data/BaseDat.MDB");
    This is OK... work in my code...
    But I want to know if there's another way to do this... without "C:/Documents and Settings/MetalTux/POOL/src" code....
    In Visual Basic I do this with "App.Path", but I don't know how I can do the same thing in Java...
    Please help me...

  • How to connect java with C

    Plz help....
    How to Connect a Java With C ....

    using the JNI, Java Native Interface. there are tons of tutorials on the web about it, that will explain far better and more completely than a few posts on a forum

  • Cant connect java with oracle

    i am new to oracle.
    i cant connect java(jdk1.3) to oracle using 'oracle.jdbc.driver.OracleDriver' in Class.forName() and DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger")
    it shows "class not found" error.
    is there any one to suggest or help me?

    you are posting in wrong forum, as this one is for SQLDeveloper-related issues only. You should post java-related issues in this forum:
    SQL Developer
    However, about your exception you have missed to put the oracle jdbc driver in the classpath.
    Download it from here:
    SQL Developer
    and see more info here:

  • How to connect java to oracle 9i

    Hi guys , i'm still beginner in oracle ,I've created a database and i need to connect a java application to it ,i mention that i'm using netbeans as IDE (tomcat server is embedded with it),please any help.

    Ok , I manage to make the connection to my DB using the help of netbeans ,but i'm only able to run sql statement using the sql editor ,but when it comes to creating a class that does the connection and execute sql statement ,the IDE tell me that there is no driver ,but in reality i'm connected to the database,here's the code i've written to access the db:
    import java.sql.*;
    * @author XPPRESP3
    public class Main {
    public static void main(String[] args) {
    Connection connection = null;
    try {
    // Load the JDBC driver
    String driverName = "oracle.jdbc.driver.OracleDriver";
    String url=" jdbc:oracle:oci8:@db1";
    connection = DriverManager.getConnection(url,"Scott","tiger");
    } catch (ClassNotFoundException e) {
    System.out.print("no DRIVER ");
    } catch (SQLException e) {
    System.out.print("no db ");

  • Noclassfound error while connecting java with oracle database

    hi all
    the source code metioned below gets compiled. but when it is run
    it gives thefollowing error.
    ClassNotFoundException: jdbc.driver.OracleDriver
    Exception in thread "main" java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(
    at java.sql.DriverManager.getConnection(
    at pract.main(
    import java.sql.*;
    class pract
    public static void main (String args []) throws SQLException
              catch(java.lang.ClassNotFoundException e)
    System.err.print("ClassNotFoundException: ");
              Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@anant:1521:student", "scott", "tiger");
    // @machineName:port:SID, userid, pas
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select * from emp");
    while (
    System.out.println (rset.getString(1)); // Print col 1
    i have included the following driver classes in the classpath
    but still im unable to connect.
    can anyone help me in solving this simple problem.

    hi ,
    you hav not stated which oracle ur using...still if u r using oracle 9i then u hav to include classes12.jar file in ur lib build classpath and then tryout following changes in code....
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn = DriverManager.getConnection("jdbc:oracle:thin:@<host>:<port>:<sid>","scott","tiger");
    hope this ll help....

  • How can connect java with 3D Max

    i want to make 3d maze by reading from text file
    for example when i read 0, then i draw wall
    when i read 1 i draw path ..and so on
    and i want to move the object in the maze by using AI techniques
    my questions are:
    - can I read from file and draw by using 3D Max and program the
    object moving using java, if yes, how can i connect the java and 3D Max
    if there are any resoures, or any other silution may help me
    please tell me about it

    I've found two loaders to load 3ds files, so if you export your models from 3ds max that should work.
    //My hyperlink option doesn't work today
    Hope it helps.

  • How to connect Java to crystal report

    How to connect java with crystal report ?
    Which are the API's for that

    In all this time you never considered searching?
    Cross post

  • Connecting JAVA with  Video Card

    Can someone tell me how to connect Java with a video card (like Matrox, dec-link, etc)?
    Because i want to display a video using that video card to a TV monitor.
    Is there any tutorial about this? and about connecting JAVA with other device?
    Thank you,

    Can someone tell me how to connect Java with a video card (like Matrox, dec-link, etc)?
    Because i want to display a video using that video card to a TV monitor.
    Is there any tutorial about this? and about connecting JAVA with other device?
    Thank you,

  • How to connect Servlet to Oracle

    so far i have see some example from internet on how to connect servlet with Oracle.. but i don't undertand the statement below
    can any expert please explain to me??
    what is ?? elab is database's name?

    so far i have see some example from internet on how to
    connect servlet with Oracle.. but i don't undertand
    the statement below
    can any expert please explain to me??
    what is ?? elab is
    database's name?jdbc:oracle: type driver
    thin: Type of driver again. Oracle distinguishes between thin/thick, but I'm not sure of the features. We use thin.
    IP Address of box where db, port:1521, db instance: elab.

  • How to connect Java Application with database!

    Dear all, now I am create a dababase application. My database use JData Store. But I don't know how to connect application with it. Can you tell me this proplem?

    Do a google search for JDBC, or go buy a book.
    You will need a JDBC driver which supports your database. Or you might be able to use the JDBC-ODBC bridge if there's an ODBC driver for your database.

  • Problem in connecting JSP with Oracle 9i.

    I am having problem in connecting JSP with Oracle 9i.
    I am using windows XP and my JDK version is 1.4. For executing JSP I am using
    "jakarta-tomcat-5.5.4-preconfigured". My database name is global.
    I have set java_home, j2ee_home, oracle_home, path, classpath as follows:
    My code is as follows:
    <%@ page language="java" %>
    <%@ page import ="java.sql.*"%>
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@global", "scott", "tiger");
    catch(SQLException e)
    I tried other program:
    <%@ page language="java" %>
    <%@ page import ="java.sql.*"%>
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:global","scott","tiger");
    I am getting following error:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 5 in the jsp file: /jsp/oracle.jsp
    Generated servlet error:
    oracle.jdbc.OracleDriver cannot be resolved or is not a type
    Thanking you in advance,

    maneesh108 wrote:
    hi this is maneesh1) Read the thread it has been answered.
    2) The thread is very old. Don't resurrect old threads.
    I'm locking this zombie thread.

Maybe you are looking for