• 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

JDBC /ODBC connectivity

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!
I am new to JDBC forum.i have oracle 7 on my machine.and want
to establish connectivity with my database.I have read JDBC2.0
from jdk1.3 but unfortunately i am not able to connect my data
with my java programme.can someone helpme with detailed
connectivity code.I dont think we need drivers to
be loaded for local programmes on machine??please help
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Sun's JDBC-ODBC bridge driver, you will have to set up an ODBC DSN to your Oracle database, which will require that you have a driver present on your local machine. You would have that driver if you had the Oracle client installed. If you are saying that your machine is both the client and the server, then I would recommend that you not try to dink around with ODBC. Sun's driver is only a reference implementation anyway, and not suitable for deployment. You can go to Oracle's web site and download their pure Java JDBC driver for free. It will be faster and easier. Then all you have to do is unzip it into your classpath and import it into your class file. Be sure to take a look at the documentation while you are out there so you can note the correct URL for your JDBC driver and it's proper connect string.
 
nachiket deshpande
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bodie!
At present i am using sun's jdbc dbc driver.and got the connectivity.now i want to insert a new row using moveToInsertRow () method but the error is ArrayIndexOutOfBound exception.Please help.my code is
import java.sql.*;
public class jump{
public static void main(String[] args)throws SQLException,
ClassNotFoundException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc dbc:dsn_sample";
Connection con=DriverManager.getConnection(url,"scott","scott");
System.out.println("Connected to DB");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("SELECT * FROM ball");
System.out.println("Successfully executed the query");
rs.moveToInsertRow();
rs.updateString("name","ram");
rs.updateInt("age",38);
rs.updateString("color","black");
rs.insertRow();
rs.moveToCurrentRow();
String s,s1;
while (rs.next()) {
s=rs.getString("name");
int i=rs.getInt("age");
s1=rs.getString("color");
System.out.println("ROW="+s +" "+i+ " "+s1);
}
rs.close();
stmt.close();
con.close();
}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic