Dommol
Dommol

Reputation: 191

accessing oracle databases through java

I'm attempting to create a java program that will allow me access to an oracle database to run sql queries. It shouldn't be too difficult of a program but I can't get an IDE to work correctly.

The sample program the teacher of the class gave us to use starts off with

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.*;
import java.util.*;

and my main issue is that the IDE I use (eclipse Helios) will not recognize the import oracle.jdbc statement. I've spent hours searching for a plugin or anything at all to fix this. I've even installed Netbeans thinking that I would have more luck there. Any suggestions?

Upvotes: 1

Views: 1194

Answers (3)

clock
clock

Reputation: 11

On notepad editor (not in eclipse..) this is type 4 connection which is faster than rest of all note: - set ur classpath for oracle search more to know about "tnsnames.ora" file which gonna help u on 4th line of this code.

import java.sql.*;

class A { 
    public static void main(String arr[]) {
        try { 
            Class.forName("oracle.jdbc.dirver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle.thin:@localhost:1521:XE","System","manager");
            Statement stmt=con.creatStatement();
            ResultSet rset=stmt.executeQuery("Select * from emp");
            while(rset.next()) {
                System.out.println(rset.getInt(1)+"\t"+rset.getInt(2));
            }
            con.close();
        } catch(Exception e) { }
    }
}

Upvotes: 0

Cris
Cris

Reputation: 5007

You have the drivers here

what i would recommend is not to use import oracle.jdbc.*; use for start just java.sql

A good link to start using that is here

In rest put the driver in the classpath as @Andrea recommended

Upvotes: 2

Andrea Girardi
Andrea Girardi

Reputation: 4427

You need to download the jar ORACLE JDBC Drivers and import it in your project on Eclipse: project -> Properties -> Java Build Path -> Libraries and "Add external libraries"

Upvotes: 6

Related Questions