The Artima Developer Community
Sponsored Link

Java Answers Forum
JDBC

8 replies on 1 page. Most recent reply: Feb 20, 2009 12:11 AM by Melody s

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

JDBC Posted: Sep 28, 2003 6:30 AM
Reply to this message Reply
Advertisement
Hi all,

I wrote this program to connect to oracle using JdbcOdbcDriver.I created a system dsn for Microsoft ODBC for Oracle named 'test'.

import java.sql.*;
import java.io.*;

public class JdbcOra{

public JdbcOra(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test","scott","tiger");

PreparedStatement p =con.prepareStatement("select * from Employee");

ResultSet r= p.executeQuery();
while(r.next()){
System.out.println(r.getString(1)+" "+r.getString(2));
}
}
catch(SQLException ee){
System.out.println(ee.getMessage());
ee.printStackTrace();
}
catch(ClassNo tFoundException e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}

public static void main(String args[]){
JdbcOra j = new JdbcOra();
}
}



It gives me the exception:

[Microsoft][ODBC driver for Oracle][Oracle]
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Sour
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcOra.<init>(JdbcOra.java:9)
at JdbcOra.main(JdbcOra.java:27)

I couldn't understand what this exception means.Is this due to any driver missing??

Thanx in advance for helping me.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: JDBC Posted: Sep 28, 2003 7:08 AM
Reply to this message Reply
I suggest to debug this code move the code out from constructor. Move the getting connection to a different method and execution of the query to a different method. Then you might be able to isolate the problem better.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: JDBC Posted: Sep 28, 2003 8:06 AM
Reply to this message Reply
		try {
			// Load the JDBC driver
			String driverName = "oracle.jdbc.OracleDriver";
			Class.forName(driverName);
			// url connection string format, a valid format is: "host:port:sid" 
			String urlString = "jdbc:oracle:thin:@hostname:port:sid";
			String userName = "yourusername";
			String password = "yourpassword";
 
			Connection connection = DriverManager.getConnection(urlString, userName, password);
			Statement sta = connection.createStatement();
			String sql = "SELECT *  FROM BLAHBLAHBLAH";
	
			ResultSet rs = sta.executeQuery(sql);
			while(rs.next()){
                           //process reult set
			}
 
		} catch (ClassNotFoundException e) {
			System.err.println("Could not find the database driver");
		} catch (SQLException e) {
			System.err.println("Could not connect to the database");
		}
 

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: JDBC Posted: Sep 28, 2003 4:32 PM
Reply to this message Reply
Charles,

Your example solves the issues with Oracle Thin driver. Even though thatÂ’s a better solution and guaranteed to work the original question uses the ODBC-JDBC Bridge.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: JDBC Posted: Sep 28, 2003 5:27 PM
Reply to this message Reply
In the oracle "scott" schema are you sure that the table is called "Employee"? I thought it was "Emp".
I don't have a sample db installed here to check.

sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

Re: JDBC Posted: Sep 29, 2003 11:07 AM
Reply to this message Reply
I am able to execute MS Access database but I cudnt do it for Oracle.Is there any specific driver that i have to install to execute Oracle database??If so where can I get that for free :-)?

Also to run Oracle using Jdbc-Odbc bridge do I need to install any driver but to execute MSAccess I didn't install anything.

sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

Re: JDBC Posted: Sep 29, 2003 11:14 AM
Reply to this message Reply
I tried using seperate methods but still the same.

The exception is thrown in my second line i.e.
Connection con=DriverManager.getConnection("Jdbc:Odbc:test","scott","tiger");

Also Employee is a table that I created.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: JDBC Posted: Sep 29, 2003 11:45 AM
Reply to this message Reply
I have never tried a connection url with mixed case, but that doesn't seem to be your problem.

What does the employee table look like?

Can you (from sql*plus) run the following and post the response here?
describe scott.employee

Also, are you able to add the employee table as a linked table in Access using your DNS ("test")?

Melody s

Posts: 1
Nickname: melodys
Registered: Feb, 2009

Re: JDBC Posted: Feb 20, 2009 12:11 AM
Reply to this message Reply
Hii.... I m facing the same problems with jdbc...Can u suggest how u solved ur prob..

Flat View: This topic has 8 replies on 1 page
Topic: socket programing and server! Previous Topic   Next Topic Topic: How to create Word doc programatically

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use