2 Replies - 4537 Views - Last Post: 26 February 2009 - 06:02 PM Rate Topic: -----

#1 Vaune  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 98
  • Joined: 25-March 08

Java Applet - Cannot access database?

Posted 26 February 2009 - 07:31 AM

Hello everyone! Hope all is well.

Well I'm making a program that generates a horoscope for a user depending on birthdate yatta yatta. I have all that working well, but when I attempt to connect to an access database to retrieve a horoscope message, I get a bunch of security errors? This applet is not run online, and connects to a local database, no internets is used in the process. My code is as follows:

public void horoscopeGen(String SIGN, Integer SEED)
	{
		java.sql.Connection conn = null;
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
			conn=DriverManager.getConnection("jdbc:odbc:horoscope","","");
			Statement stmt=conn.createStatement();
			ResultSet rs=stmt.executeQuery("SELECT "+ SIGN + "FROM HoroMessages WHERE ID = " + SEED + ";");
			conn.close();
			stmt.close();
		}//closes try
		catch(SQLException s)
		{
		}//end catch
		catch (ClassNotFoundException e)
		{
		}
		catch(InstantiationException m)
		{
		}
		catch(IllegalAccessException n)
		{
		}
	}//endmethod



And it is called with:
Random r = new Random();
int i = r.nextInt(4) + 1;
horoscopeDatabase hDB = new horoscopeDatabase();
hDB.horoscopeGen(sign,i);



My error messages that I am getting is:
Exception in thread "Awt-EventQueue-1" java.security.AccessControlException: access denied
(java.lang.RuntimePermission access ClassInPackage.sun.jdbc.odbc)

Followed by alot of other messages. What could be causing this? Am I improperly trying to talk with the database? Are Applets not allowed to connect to a database?

My table in the database is named HoroMessages and each field name is Sign. I am attempting to call a message depending on a random number between 1 and 4 (This is the ID field).

I'm not sure what I'm doing wrong as this is the first time I've used databases in java.

Any thoughts? Any more information needed?

Is This A Good Question/Topic? 0
  • +

Replies To: Java Applet - Cannot access database?

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Java Applet - Cannot access database?

Posted 26 February 2009 - 09:22 AM

Your applet connects to a database on your local server? If not it wont be able to access a database on a server other than your local one as long as it is not signed applet, check out this link, t may be helpful http://faq.javaranch...LocalFileSystem, good luck ;)
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Java Applet - Cannot access database?

Posted 26 February 2009 - 06:02 PM

Applet cannot normaly access the local file system
So you have to pass through the network localhost::....
and your Applet has, I think, also to be download from the network (even if used on the same machine) so Java will know that both the Applet and the database are coming from the same host
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1