wood burning stoves 2.0*
The moose likes JDBC and the fly likes Connecting Java Application with a Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting Java Application with a Database" Watch "Connecting Java Application with a Database" New topic
Author

Connecting Java Application with a Database

Pranit Sonawane
Ranch Hand

Joined: Jul 29, 2011
Posts: 155

Hello i'm trying to connect my java application to the oracle database server. I use oracle 10 g and want to connect my application to this database management system. I'm using windows 7 64 bit as an operating system and not able to find the Oracle ODBC Driver while creating a DSN(Data Source Name). Please Help. Many Thanks!!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Don't do that. If you have an Oracle database then the way to access it from Java is via JDBC, not ODBC. So get the Oracle JDBC driver which corresponds to your version of the Oracle database and work with that.

If you don't know about JDBC then your first step should be to read a JDBC tutorial (Google keywords: jdbc tutorial).
Pranit Sonawane
Ranch Hand

Joined: Jul 29, 2011
Posts: 155

Paul Clapham wrote:Don't do that. If you have an Oracle database then the way to access it from Java is via JDBC, not ODBC. So get the Oracle JDBC driver which corresponds to your version of the Oracle database and work with that.

If you don't know about JDBC then your first step should be to read a JDBC tutorial (Google keywords: jdbc tutorial).


so how will i connect it to oracle 10 g??
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

it has been 10 years since i did this sort of thing but there was what they called jdbc-odbc bridge. made it very simple. like Paul suggested google JDBC tutorial


SCJP
Visit my download page
Pranit Sonawane
Ranch Hand

Joined: Jul 29, 2011
Posts: 155

Randall Twede wrote:it has been 10 years since i did this sort of thing but there was what they called jdbc-odbc bridge. made it very simple. like Paul suggested google JDBC tutorial

That's what am gonna do...but it needs a driver to create a DSN and am not able to find the driver in list... please Help me how can i connect it to the database if i have oracle 10 g using jdbc-odbc bridge
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Pranit Sonawane wrote:That's what am gonna do...but it needs a driver to create a DSN and am not able to find the driver in list... please Help me how can i connect it to the database if i have oracle 10 g using jdbc-odbc bridge

Download drivers from Oracle - here: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Get the newest version for 11g, it is compatible with earlier versions of the database - 9g and 10g.
ojdbc6.jar is for Java 1.6, ojdbc5.jar works with Java 1.5, choose one for your java version and place this jar in the classpath.
The rest is in the tutorial: http://docs.oracle.com/javase/tutorial/jdbc/index.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Pranit Sonawane wrote:
Randall Twede wrote:it has been 10 years since i did this sort of thing but there was what they called jdbc-odbc bridge. made it very simple. like Paul suggested google JDBC tutorial

That's what am gonna do...but it needs a driver to create a DSN and am not able to find the driver in list... please Help me how can i connect it to the database if i have oracle 10 g using jdbc-odbc bridge


I repeat... DO NOT use ODBC for this. The reason? The JDBC-ODBC driver is a piece of junk. Instead, read what Ireneusz posted and set up a proper JDBC environment.
Rumesh Eranga
Ranch Hand

Joined: Jan 26, 2011
Posts: 34



When creating the connection object Please check how to give oracle db dtails to this argument.If you using my sql it shud be like above.

Hope this helps.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Except you should use an Oracle driver for connecting to an Oracle database, a MySQL driver to connect to a MySQL database and an ODBC driver to connect to an ODBC data source. That example uses a driver for one type, then attempts to connect to another.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
raj pandey
Greenhorn

Joined: Jan 13, 2012
Posts: 7
Ireneusz Kordal wrote:
Pranit Sonawane wrote:That's what am gonna do...but it needs a driver to create a DSN and am not able to find the driver in list... please Help me how can i connect it to the database if i have oracle 10 g using jdbc-odbc bridge

Download drivers from Oracle - here: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Get the newest version for 11g, it is compatible with earlier versions of the database - 9g and 10g.
ojdbc6.jar is for Java 1.6, ojdbc5.jar works with Java 1.5, choose one for your java version and place this jar in the classpath.
The rest is in the tutorial: http://docs.oracle.com/javase/tutorial/jdbc/index.html

hi all i have a doubt.as discussed above i follow all steps as Ireneusz said...
but still i dont find any solutions...
i have already add ojdbc6.jar in class path and i am getting "java.sql.SQLException: No suitable driver found for http://127.0.0.1:8080/apex"
please help me :-(..

i tried this:--

package pkg1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Manager1 {
public static void main(String[] args)
throws SQLException,ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("http://127.0.0.1:8080/apex","system","dkiran");

Statement stmt=con.createStatement();
String sql="CREATE TABLE EMP(ID NUMBER(90),NAME VARCHAR2(20))";

stmt.execute(sql);
System.out.println("done");

}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You can't connect to an ODBC database using HTTP. You need to use an ODBC connection String. The one matching your driver class is not "http://127.0.0.1:8080/apex" but "jdbc:odbc:apex", assuming that "apex" is the ODBC name.
raj pandey
Greenhorn

Joined: Jan 13, 2012
Posts: 7
Rob Spoor wrote:You can't connect to an ODBC database using HTTP. You need to use an ODBC connection String. The one matching your driver class is not "http://127.0.0.1:8080/apex" but "jdbc:odbc:apex", assuming that "apex" is the ODBC name.

Thanks Rob for quick response...
where i can get that connection string.
i am using windows 7 64bit and oracle 10g XE.
i google for connection string..but still didn't find any suitable match .....
can you explain in steps to connect to the database for simple java program.

thanks in advance !!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Start with reading this. After that, all that remains is the driver class and the connection String. This depends on the database server you're connecting to. The driver's documentation should tell you all you need. For Oracle the class is oracle.jdbc.driver.OracleDriver and the connection String for direct access (without having to install any Oracle software other than the driver JAR file) is "jdbc:oracle:thin:@HOST:PORT:DATABASE" where HOST is the database server host, PORT is the port the database server is running on (1521 by default), and DATABASE is your database name.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connecting Java Application with a Database
 
Similar Threads
JDBC driver confusion
message-driven bean to wrap legacy applications
JSP deployed to OAS urgent
Any alternative to JDBC???
JBoss Classpath