Hello everybody,
I'm developing my first Java Applet and I'm already behind a wall. I spent a lot of time trying to understad it and solve it but nothing!!!
When I try to connect to the db I receive the following error:
access denied ("java.util.PropertyPermission" "oracle.net.tns_admin" "read")
in the source code row
con = DriverManager.getConnection(connect_string);
A similar not applet project works fine...
This is my HTML:
================================================== ====================
<html>
<head>
<title>TEST</title>
</head>
<body>
<h1>TEST</h1>
This is a test<p>
<hr>
<applet codebase="file:///D:/Java Tutorials/Test1/build/classes"
code="test/RunProcApplet.class" width=800 height=275>
<param name="text" value="Test1">
<hr>
Your browser does not support Java applet.
<hr>
</applet>
<hr>
================================================== ====================
an this is my java:
================================================== ====================
// Import the JDBC classes
import java.awt.*;
import java.sql.*;
import oracle.jdbc.*;
import oracle.sql.*;
public class RunProcApplet extends java.applet.Applet
{
// The connect string
static final String connect_string = "jdbcracle:thin:USER/PASSWORD@//SERVER:1521/SID";
// The query we will execute
static final String query = "select * from TAB1";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
// The button to push for executing the query
Button execute_button;
// The place where to dump the query result
TextArea output;
// Create the User Interface
public void init ()
{
this.setLayout (new BorderLayout ());
Panel p = new Panel ();
p.setLayout (new FlowLayout (FlowLayout.LEFT));
execute_button = new Button ("Start");
p.add (execute_button);
this.add ("North", p);
output = new TextArea("", 8, 200, TextArea.SCROLLBARS_BOTH);
this.add ("Center", output);
}
// Do the work
@Override
public boolean action (Event ev, Object arg)
{
if (ev.target == execute_button)
{
try
{
output.append("Click Button\n");
// See if we need to open the connection to the database
if (con == null)
{
// Load the JDBC driver
output.append ("Registering driver...\n");
Class.forName("oracle.jdbc.driver.OracleDriver");
// Connect to the databse
output.append ("Connecting to " + connect_string + "\n");
con = DriverManager.getConnection(connect_string);
output.append ("Connected\n");
}
// Create a statement
stmt = con.createStatement();
// Execute the query
output.append ("Executing query " + query + "\n");
rs = stmt.executeQuery(query);
// Dump the result
while(rs.next())
{
output.append(rs.getString("COL1") + "\t");
output.append(rs.getString("COL2"));
}
// We're done
output.append ("done.\n");
}
catch (Exception e)
{
// Oops
output.append("Error!!!\n");
output.append (e.getMessage () + "\n");
}
return true;
}
else
{
return false;
}
}
}
================================================== ====================