Hi..I am trying to connect oracle which is on my pc.i am using oracle 9i.
i am creating 1 customer table & trying to display it.

import java.sql.*;
import java.net.*;
public class JdbcDemo{
	public static void main(String args[]){
		Driver d;
		Connection con;
		Statement stmt ;
		ResultSet rs;

		try{
   			d=(Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
      			System.out.println("Got driver");
   			con =DriverManager.getConnection("jdbc:odbc:thin:@localhost:1521:XE","scott","tiger");
   		//	con =DriverManager.getConnection("jdbc:oracle:thin:2030:oracle","scott","tiger");
  			
  			System.out.println("Got Connection");
  		
  			stmt = con.createStatement();
			System.out.println("Statement object created");
   			rs= stmt.executeQuery("select * from customer");
   			while(rs.next()){
       		
					System.out.println(rs.getString(1));
       				System.out.println(rs.getString(2));												
					System.out.println(rs.getString(1)+"  "+rs.getString(2));
			}
		}
		catch(IllegalAccessException e){
			System.out.println("in IllegalAccess exception");
			e.printStackTrace( System.out );


		}
		catch(ClassNotFoundException e){
			System.out.println("in class not Found exception");
			e.printStackTrace( System.out );

		}
		catch(SQLException e){
			System.out.println("in SQLException exception");
			e.printStackTrace( System.out );

		}
		catch(Exception e){
			System.out.println("in exception");
			e.printStackTrace( System.out );

		}
	}
}

It gives Error.....

Got driver
in SQLException exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not fou
nd and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
23)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Jdbc2.main(Jdbc2.java:13)

import java.sql.*;import java.net.*;
public class JdbcDemo{
	public static void main(String args[]){
		
		Connection con;
		Statement stmt ;
		ResultSet rs;

		try{
   			Class.forName("oracle.jdbc.driver.OracleDriver");
      			
   			con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orclt1","scott","tiger");
   		
  			
  			System.out.println("Got Connection");
  		
  			stmt = con.createStatement();
			System.out.println("Statement object created");
   			rs= stmt.executeQuery("select * from customer");
   			while(rs.next()){
       		System.out.println(rs.getInt(1)+"  "+rs.getString(2));
			System.out.println("----------------------");
			
			}//end of while
		}//end of try
		
		catch(ClassNotFoundException e){
			System.out.println(e);
		}
		catch(SQLException e){
			System.out.println(e);
		}
		catch(Exception e){
			System.out.println(e);
		}
	}
}

This works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.