dcsimg
Java: calling jdbc.odbc from browser
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yisrael_Harris
Posted On:   Friday, April 18, 2003 04:46 AM

I would like to have the browser call a java program which, among other things, executes database record retrievals. I have the following java code working correctly: import java.sql.*; public class db { public static void main (String[] args) { Connection conn; ResultSet res; Statement stat; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:test"); stat = conn.createStatement(); res = stat.executeQuery("Select field1 from table1"); res.next(); System.out.println(res.getString(1)); } catch (Exception e) { System.out.println(   More>>

I would like to have the browser call a java program which, among other things, executes database record retrievals.

I have the following java code working correctly:

import java.sql.*;

public class db {

public static void main (String[] args) {

Connection conn;
ResultSet res;
Statement stat;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:test");
stat = conn.createStatement();
res = stat.executeQuery("Select field1 from table1");
res.next();
System.out.println(res.getString(1));
}
catch (Exception e) {
System.out.println("Error" + e);
}
}
}

I run this code successfully in the command line ("java db").

What I want is for this code to run in the browser. The only method I know how to do so is through an Applet.

The problem is that when I try to run the code as above in an applet, it fails on the following line:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

It throws an exception, saying:

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver.

The java literature I read warned me about this problem.

However, I do need to run my java sql code from the browser, so any ideas of how to do so would be much appreciated.

   <<Less

Re: Java: calling jdbc.odbc from browser

Posted By:   Stephen_McConnell  
Posted On:   Friday, April 18, 2003 05:09 AM

You need to jar the JDBC driver with your applet and reference the jar file in your Applet tag...


You might want to look at another solution, if you have large rowsets.


Most implementations of remote database calls return something like a cursor. Each time you examine a rowset, you make a call back to the database server and it returns the row set..... Very slow!!!!


What I have implemented is creating a RMI program on the server side that makes the query call packages up the information you want in a Vector of objects and then returns the Vector back to the applet. This speeds up the process 1000% times.


Stephen McConnell

About | Sitemap | Contact