473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Chart Applet "Applet not initialized"

JustRun
127 100+
Hi,

I'm new to Java "I loved it" and i'm stuck with a Chart Applet
i'm trying to give the pie chart its values from my database.
Actually the database class works when i tested it in main method buut when i put it inside the applet it gives me this
"java.security.AccessControlException: access denied (java.util.PropertyPermission file.encoding read)"

Also for the pie chart itself, it works fine as an application, but when i put it in the applet it says: "The applet is sot initialized"

I tried to make it as Thread and put the connection in the run() but the same error.

// Database Class
Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3. public class DBConnection {
  4.     String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  5.     String url = "jdbc:odbc:BrokerSystemDSN";
  6.     String query = "SELECT CompanyName, ExchangeRate FROM StochHistoryTable";
  7.     String text;
  8.     public Connection cnn;
  9.  
  10.     public DBConnection(){
  11.         try{
  12.             Class.forName(driver).newInstance();
  13.             System.out.println("Driver Loaded");    
  14.         }catch(Exception ex){
  15.             System.out.println("Failed to load driver");
  16.         }
  17.     }
  18.  
  19.     public void OpenConnection() {
  20.         try{
  21.             cnn = DriverManager.getConnection(url);
  22.             System.out.println("Connection Established");
  23.         }catch(SQLException e){
  24.             System.out.println("Failed to establish Connection");
  25.         }
  26.     }    
  27.  
  28.     public void CloseConnection() {
  29.         try{
  30.             cnn.close();
  31.         }catch(SQLException eClose){
  32.             System.out.println("cannot close database");
  33.         }
  34.     }
  35.  
  36.     public Connection getConnection(){
  37.         return cnn;
  38.     }
  39.  
  40.     public void TestStatment()
  41.     {
  42.         try {
  43.             Statement stmt = cnn.createStatement();
  44.               ResultSet rs = stmt.executeQuery(query);
  45.               while (rs.next()){
  46.                 String tmpName = rs.getString("CompanyName");
  47.                   float tmpPrice = rs.getFloat("ExchangeRate");
  48.                   text += tmpName + "     " + tmpPrice;
  49.                   System.out.println(text);
  50.               }        
  51.               stmt.close();
  52.               cnn.close();
  53.         }
  54.         catch (Exception ex) {
  55.             System.out.println("cannot create statement");
  56.         }
  57.     }
  58.     // Tests
  59.     public static void main (String args[]){
  60.         DBConnection dBConnection = new DBConnection();
  61.         dBConnection.OpenConnection();
  62.         dBConnection.TestStatment();
  63.     }    
  64. }
  65.  
// APPLET Code

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * @(#)OutputApplet.java
  3.  *
  4.  * OutputApplet Applet application
  5.  *
  6.  * @author 
  7.  * @version 1.00 2008/9/13
  8.  */
  9.  
  10. import java.awt.*;
  11. import java.applet.*;
  12. import java.awt.Graphics;
  13. import java.util.Vector;
  14. import java.sql.*;
  15.  
  16. public class OutputApplet extends Applet implements Runnable{
  17.     DBConnection dBConnection = new DBConnection();
  18.     private String text;
  19.     private Statement stmt;
  20.     private ResultSet rs;
  21.     private String query = "SELECT CompanyName, ExchangeRate FROM StochHistoryTable";
  22.     private Thread worker;
  23.     private Vector queryResults;
  24.     private String message = "Initializing";
  25.  
  26.  
  27.     public synchronized void start() {
  28.       // Every time "start" is called we create a worker thread to
  29.       // re-evaluate the database query.
  30.       if (worker == null) {
  31.           message = "Connecting to database";
  32.         worker = new Thread(this);
  33.         worker.start();
  34.         }
  35.     }
  36.  
  37.      /**
  38.      * The "run" method is called from the worker thread.  Notice that
  39.      * because this method is doing potentially slow databases accesses
  40.      * we avoid making it a synchronized method.
  41.      */
  42.  
  43.     public void run() {
  44.  
  45.     }
  46.     public void init() {
  47.         dBConnection.OpenConnection();
  48.         try {
  49.             stmt = dBConnection.cnn.createStatement();
  50.             rs = stmt.executeQuery(query);
  51.             while (rs.next()){
  52.                 String tmpName = rs.getString("CompanyName");
  53.                   float tmpPrice = rs.getFloat("ExchangeRate");
  54.                   text += tmpName + "     " + tmpPrice;
  55.                   //System.out.println(text);
  56.               }        
  57.         }
  58.         catch (Exception ex) {
  59.             System.out.println("cannot create statement");
  60.         }
  61.         finally {
  62.             dBConnection.CloseConnection();
  63.         }
  64.     }
  65.  
  66.     public void paint(Graphics g) {
  67.  
  68.         g.drawString(text, 10, 65);
  69.     }
  70. }
  71.  
Any ideas.
Sep 14 '08 #1
2 3337
Dököll
2,364 Expert 2GB
If this does not do it for you, I don't know what will, let us know if it works:
http://www.javaworld.com/community/node/1168

In a bit!

Dököll
Nov 18 '08 #2
r035198x
13,262 8TB
If this does not do it for you, I don't know what will, let us know if it works:
http://www.javaworld.com/community/node/1168

In a bit!

Dököll
That link won't help much there.
The problem is that applets are run in browsers and therefore are client side programs with the same restrictions as other client side scripts e.g Javascript.

The restrictions imposed upon applets and how to get past some of them are well explained in Sun's applets tutorial

P.S Fewer and fewer people are using applets these days.
Nov 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: WMMorgan | last post by:
There's a website I like to visit that has an user-interactive java application. There's a "visual applet" component and "control applet" component. (No, it's not an adult or porno site.) But...
0
by: Ben | last post by:
Hi, I have a graphics library I'm writing in C++ (that is not COM and is not managed, just plain ol' C++ and opengl) but would like to "demo" the rendering capabilities of this library from a...
6
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 ...
0
by: Manuel | last post by:
I'm using the SQLHelper class to do an insert and get the identity field this way: -------------- Dim sql As String = "INSERT INTO () VALUES ('MyMessage');SELECT SCOPE_IDENTITY()" Dim ds As...
7
by: instruo | last post by:
Hi all, I'm curious if Microsoft has any plans of taking the .Net framework to the web in the same kind of capacity as Java Applets do. I've read that using the <object> tag, one can embed a...
0
by: RAM | last post by:
Hello, On SomeDataList.DataBind() I receive InvalidOperationException "The ConnectionString property has not been initialized." In a few places above same SomeDataList.DataBind() commands work...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
0
by: dhillarun | last post by:
Hi all, Problem (in short): Disabling the applet cache. Problem (in detail): I have developed an Applet application. I am creating the contents of the applet by reading a text file in...
2
by: Richard Maher | last post by:
Hi, Can someone please tell me the strategy(ies) used by Java (the Security Manager or whatever) to determine if a given IP address conforms to the definition of the codebase from which an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.