I must be even more green. I am trying to use the combo box in an
applet while populating the combo box with data from a MS Access 2000 MDB file. I get the following errors:
java.security.AccessControlException: access denied (java.lang.RuntimePermission
accessClassInPackage.sun.jdbc.odbc)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:150
1)
at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:169)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at TestBudget.init(TestBudget.java:27)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)
ANY IDEAS?
My code looks like:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;
import java.text.*;
public class SelectBudget extends Applet implements ActionListener,FocusListener
{
public void init()
{
// Define variables used in program
String[] datab = new String[500];
int i = 0;
datab[0] = "Init";
Connection a_connection = null;
Statement a_statement = null;
ResultSet rs = null;
DateFormat myFormat = new SimpleDateFormat("MM/dd/yyyy");
// Find database driver
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{
System.err.println("Cannot find database driver" + e);
System.exit(1);
}
// Attempt to make a connection to the database
try
{
a_connection = DriverManager.getConnection("jdbc
dbc:TestNew","","");
}
catch (SQLException e)
{
System.err.println("Cannot connect to database" + e);
System.exit(1);
}
// Setup to create a SQL statement
try
{
a_statement = a_connection.createStatement();
}
catch (SQLException e)
{
System.err.println("Cannot create statement" + e);
System.exit(1);
}
// Building the SQL statement to read the EMPLOYEE Database and display the results
try
{
String qryString = "SELECT TranDate, TranDesc, TranAmount, TranType FROM Budget";
rs = a_statement.executeQuery(qryString);
while(rs.next())
{
Date tranDate = rs.getDate(1);
String tranDesc = rs.getString(2);
String tranAmt = rs.getString(3);
String tranType = rs.getString(4);
datab[i] = tranDesc + " " + tranAmt + " " + tranDate + " " + tranType;
i++;
}
}
catch (SQLException e)
{
System.err.println("Error in reading database" + e);
System.exit(1);
}
JComboBox combo = new JComboBox(datab);
add(combo);
combo.requestFocus();
combo.addActionListener(this);
invalidate();
validate();
}
public void actionPerformed(ActionEvent thisEvent)
{ }
public void focusGained(FocusEvent e)
{ }
//Must be coded to implement FocusListener
public void focusLost(FocusEvent e) { }
}