Solved

Simple SQL Applet

Posted on 2002-05-12
4
426 Views
Last Modified: 2013-12-29
Hey all, I'm trying to write my first SQL applet which connects to an Access database.  I'm just trying to get the framework of this to work so I can experiement with it later.  

I am using an ODBC bridge driver.  
Here is my error:

java.security.AccessControlException: access denied (java.lang.RuntimePermissi
 accessClassInPackage.sun.jdbc.odbc)
        at java.security.AccessControlContext.checkPermission(AccessControlCon
xt.java:270)
        at java.security.AccessController.checkPermission(AccessController.jav
401)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
        at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1
3)
        at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:16

        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:109)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:130)
        at SqlTest.init(SqlTest.java:39)
        at sun.applet.AppletPanel.run(AppletPanel.java:341)
        at java.lang.Thread.run(Thread.java:536)



Here is my Applet: VERY SIMPLE -- Dont laugh:


/*
 * @(#)SqlTest.java 1.0 02/04/10
 *
 * You can modify the template of this file in the
 * directory ..\JCreator\Templates\Template_2\Project_Name.java
 *
 * You can also create your own project template by making a new
 * folder in the directory ..\JCreator\Template\. Use the other
 * templates as examples.
 *
 */


import java.awt.*;
import java.applet.*;
import java.sql.*;
import javax.swing.*;


public class SqlTest extends JApplet {
     
     String fName = new String();
     String lName = new String();
     
     public void init() {
         
          String url = "jdbc:odbc:dsnTest";
          String sqlString = "Select * Customer";
         
         
          ResultSet rs;
          Statement strSQL;
         
          Connection con;
         
          try
          {
               //create instance of the driver
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               
               //creat the connection
               con = DriverManager.getConnection(url);
               
               //make sql statment
               strSQL = con.createStatement();
               rs = strSQL.executeQuery(sqlString);
               
               
               while(rs.next())
               {
                   
                    fName = rs.getString("First Name");
                    lName = rs.getString("Last Name");
                    if(fName == null)
                         System.out.println("NULL!!");
                    if(lName == null)
                         System.out.println("Last name is null");
               }
                   
         
                             
          }
          //catch all exceptions
          catch(Exception e)
          {
               e.printStackTrace();
               return;
          }

         
     }

     public void paint(Graphics g)
     {
         
          g.drawString("First Name: " + fName, 50, 60);
         
         
     }
}
0
Comment
Question by:smartin7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7005526
 The exception you are getting is thrown by the applet security manager and it does not have to do with errors in your code. Bare in mind that applets can only communicate with the database server that resides on the same machine where Applet was downloaded from. You cannot connect to any other server without first signing the Applet with a digital certificate.

  Hope it helps.
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 7005530
0
 

Author Comment

by:smartin7
ID: 7006483
Girionis,
   Thanks for the information, thats exactly what I need.  It appears I need to create a policy file.  This is a great link.  Thanks again!

-Scott
0
 
LVL 35

Expert Comment

by:girionis
ID: 7007048
 No problem. Thank you for the points :-)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

739 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