• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting Java Application with a Database

 
Ranch Hand
Posts: 172
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 172
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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??
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Pranit Sonawane
Ranch Hand
Posts: 172
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic