Solved

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

Posted on 2001-06-27
6
191 Views
Last Modified: 2013-11-23
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
Comment
Question by:frankjava
6 Comments
 
LVL 1

Expert Comment

by:viswa081400
Comment Utility
Can you add some piece of code and error info??
0
 

Author Comment

by:frankjava
Comment Utility
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
 
LVL 1

Expert Comment

by:viswa081400
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:frankjava
Comment Utility
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
 
LVL 5

Expert Comment

by:vemul
Comment Utility
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
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now