• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

createstatement: applet does not use jdbc 2 or above, same code is ok in application

I am using createstatement and the absolute method in an applet to load a picture from a SQL 7 database, using JDataconnect 2.0 as driver.

While the code works fine in an application, in the applet it produces java.sql.resultset ... method absolute not found  (same with createstatement)

I run the applet locally against Personal Web Server, with http etc... The database dataserver reports a database connection. No problem there.

I have tried everything under the sun with the archive clause in the html code, jars in the web root dir, locating which jars are actually consulted when compiling.

To no avail. I can only make it work using jdbc 1.2 methods.

So ... help !

Thanks

frank@space95.sc
0
frankjava
Asked:
frankjava
1 Solution
 
viswa081400Commented:
Can you add some piece of code and error info??
0
 
frankjavaAuthor Commented:
The error produced is 'nosuchmethoderror: java.sql.resultset ... method
absolute not found ' , i.e. when I move the mouse over the applet in IE5

In Netscape it says 'ERROR, CAN'T START APPLET'



The code: (it says DOES NOT WORK next to the createstatement and absolute that cause the applet not to work)



/*
<p><applet codebase="." code="PhotoUpl" align="baseline" width="711"
height="474" archive="jdbc-3_0-pfd2-classes.zip"></applet></p>
*/

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import java.sql.*;
//import javax.sql.*;
import java.io.*;
import java.util.*;
//import com.sun.java.swing.UIManager;
import borland.jbcl.util.*;
import com.sun.java.swing.*;

public class PhotoUpl extends Applet {
  XYLayout xYLayout1 = new XYLayout();
  boolean isStandalone = false;
  TextControl textControl1 = new TextControl();
  TextControl textControl2 = new TextControl();
///  ImageControl imageControl1 = new ImageControl();

//  ImageLoader ImageLoader1;
  TextControl textControl3 = new TextControl();
  ResultSet rs = null;
  ResultSetMetaData rsMetaData;
  Connection c;
//  Statement s;
  StringBuffer SQLstat = new StringBuffer("");
  StringBuffer mMessage = new StringBuffer("");

  Image Image1;
  Graphics gIm;
  Dimension dimIm;

  public void init() {
    try {
    jbInit();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    xYLayout1.setWidth(519);
    xYLayout1.setHeight(370);
    textControl1.setFont(new Font("Dialog", 1, 14));
    textControl1.setText("Establishment:");
    textControl2.setFont(new Font("Dialog", 0, 30));
    textControl2.setText("Picture Uploading to Database");
    textControl3.setEdgeColor(new Color(0, 0, 218));
    textControl3.setForeground(new Color(0, 0, 168));
    textControl3.setFont(new Font("Helvetica", 1, 13));
    textControl3.setText("Some establishment");
    this.setLayout(xYLayout1);
    this.add(textControl1, new XYConstraints(16, 75, 112, -1));
    this.add(textControl2, new XYConstraints(14, 13, -1, -1));
///    this.add(imageControl1, new XYConstraints(17, 139, 282, 178));
    this.add(textControl3, new XYConstraints(17, 104, 454, -1));

    Driver drv = null;
    try  {
      drv = (Driver) Class.forName("JData2_0.sql.$Driver").newInstance();
//      drv = (Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    }
    catch (Exception e) {
        System.out.println("Cannot load the driver, reason:"+e.toString());
        System.out.println("Most likely the Java class path is incorrect.");
        mMessage.append("Test 1 !!!!!!!!!!!!!!! ");
    }



    try {
      c =java.sql.DriverManager.getConnection(       // best one
        "jdbc:JDataConnect://192.168.10.152/BOE1:frank10:frank11");
//      String url = "jdbc:odbc:BOE1";
//      c = java.sql.DriverManager.getConnection(url, "frank10", "frank11");

      if (c == null) {
//        mMessage.setLength(0);
        mMessage.append(" connection is null ! ");
        repaint();
      } else {
        mMessage.append(" connection is not null ! ");
        repaint();
///        return;
      }

      mMessage.append("Statement about to be prepared");
      repaint();
      mMessage.append("Statement prepared");
      repaint();


/////////// the createstatement below is jdbc 2, see the parameters
/////////// I seem to have access to the 1.2 only ???? See also absolute method !
// most likely correct; the overloaded createstatement with parameters does not work
// but the old one of jdbc 1.2 without parameters does work

//      Statement s = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
//                             ResultSet.CONCUR_UPDATABLE);    DOES NOT WORK !!!!!!!!!
      Statement s = c.createStatement();
      rs = s.executeQuery("SELECT * FROM HSCODE where no like '%0101%' order by no");

      if (rs == null) {
        mMessage.append(" resultset not available ! ");
        repaint();
      } else {
        mMessage.append(" rs ok ! ");
        repaint();
///        return;
      }

    }
    catch (Exception e) {
//      System.out.println("Error connecting or reading table:"+e.getMessage());
      mMessage.setLength(0);
      if (c == null) {
//        mMessage.setLength(0);
        mMessage.append(" The connection is null ! ");
      } else {
        mMessage.append(" The connection is not null ! ");
      }
      mMessage.append("test 6");
  //    repaint();
    }

//    mMessage.setLength(0);
    mMessage.append(""test);
    try {

//      rs.next();

      rs.absolute(1);             //    DOES NOT WORK !!!!!!!!!
      InputStream Is1 = rs.getBinaryStream(7);
      if (Is1 == null) {
        mMessage.append("getBinaryStream problem");
        repaint();
//        return;
      }
////      InputStream Is1 = getClass().getResourceAsStream("Image034.jpg");

      byte[] ByteIm1 = new byte[Is1.available()];
      Toolkit Toolkit1 = Toolkit.getDefaultToolkit();
      Is1.read(ByteIm1);   // replaces previous line
      Image1 = Toolkit1.createImage(ByteIm1);
      repaint();    //this works !!!!!!!
    }
    catch (Exception e) {
//      mMessage.setLength(0);
      mMessage.append("test 3 : ");
      mMessage.append(e.getMessage());
      repaint();
//      System.out.println("Error with getBinaryStream:"+e.getMessage());
    }




  }




  public void start() {
  }



  public void paint(Graphics g) {

    if (Image1 == null) {
//      mMessage.setLength(0);
      mMessage.append(" image is null ! ");
    }
    else {
//      mMessage.setLength(0);
      mMessage.append("there is an image");
      g.drawImage(Image1, 10, 100, null);
    }
    g.drawString(mMessage.toString(),10,100);
  }




//Get Applet information

  public String getAppletInfo() {
    return "Applet Information";
  }


  public String[][] getParameterInfo() {
    return null;
  }

  void buttonControl1_actionPerformed(ActionEvent e) {

  }
}

0
 
viswa081400Commented:
Does your web server and database reside on the same machine???

Applets can make connections only to the machine where it resides.

So check that out.

good luck!!

-viswa
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
frankjavaAuthor Commented:
I'm running Win98, with SQL server 7, and Personal Web Server all on the same machine. I'm calling my applet from a HTLM which I load with HTTP in IE5 or Netscape. Everything on the same machine.

A connection is established. JDataconnect 2.0 is a type 3 driver with has a dataserver running (of course, this very machine), and the DOS box reports a connection being established.

Am I contravening something by doing everything locally ?

Regards

Frank
0
 
vemulCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 
moduloCommented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now