Cannot connect java with oracle

Status
Not open for further replies.

nitinm

Broken In
Hiplease help as i have problem connecting java with oracle the connectioncode which i m implementing is working in my college but not a my place

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con = DriverManager.getConnection("jdbc:Oracle:thin:mad://ip address of college:1521/orcl9i", "name", "password");


as i m entering the loop back address i.e 127.0.0.1 which is not accepting
 
Last edited:

Faun

Wahahaha~!
Staff member
yeah the loopback is for when the server is runnin on same computer
Code:
import java.sql.*;
class dbAccess {
  public static void main (String args []) throws SQLException
  {
    Connection con=null;
        try {
              Class.forName ("oracle.jdbc.driver.OracleDriver");
        System.out.println("Driver loaded successfully");
        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:dsn","scott","tiger");
                                              // @machineName:port:SID,   userid,  password
        System.out.println("connection established");
        Statement db_statement = con.createStatement();
        // Create a simple table, which stores an employee ID and name
        db_statement.executeUpdate("create table employee( empid varchar2(5), firstname varchar2(10), salary number(7))");
    
        // Insert an employee, so the table contains data
        db_statement.executeUpdate("insert into employee values('1234','JohnDoe',1234567)");


        // Execute query
        ResultSet result = db_statement.executeQuery("select * from employee");

        // While more rows exist, print them
        while (result.next() )
        {
        // Use the getInt method to obtain emp. id
        System.out.println ("ID : " + result.getString("empid"));

        // Use the getString method to obtain emp. name
        System.out.println ("Name : " + result.getString("firstname"));
        System.out.println ("Salary : " + result.getInt("salary"));
        //System.out.println ();
        }
        
        // Commit changes
        //con.commit();

            
        } catch (ClassNotFoundException e) {
              e.printStackTrace();

        }

*www.exampledepot.com/egs/java.sql/ConnectOracle.html
 
Status
Not open for further replies.
Top Bottom