Meaningless Drivel is fun!*
The moose likes Applets and the fly likes Same old problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Same old problem?" Watch "Same old problem?" New topic
Author

Same old problem?

Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi all,

I have an applet and hsqldb driver on myjavaserver.com. This is only a test version applet right now.
Simpletext driver were working locally, but it is not useful for the net.
So I used the hsqldb driver and now I am getting this problem.

DataApplet java.sql.SQLException: File input/output error: java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)


I have tried to modify the .java.properties file in user home directory.

If you want to see it yourself


http://www.myjavaserver.com/~adilj/dataapplet.html


Is it the same old problem of applets not making connection to databases? but I think that it is making connection but something local is causing problem. Even Simpletext let applet make connection to database


Thanks in advance,

Maki Jav

[ December 05, 2007: Message edited by: Maki Jav ]
[ December 16, 2007: Message edited by: Maki Jav ]

Help gets you when you need it!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

I don't know what you mean about "the same old problem of applets not making connection to databases", but it is indeed the same old problem of applets not being allowed access to various data on the client's machine. The error message is actually very informative: some code tried to read the user.dir system property, and was prevented by the SecurityManager.

Hsqldb's main claim to fame is as an in-core, flat-file based database. There might be a network driver for it, but I'm not sure. In any case, it appears that the database code in your applet is trying to access the user's filesystem, which is a no-no for an unsigned applet. Make sure you understand the database configuration you're using: is there a server process on your server machine which the applet is going to contact, or is it just the standard Hsqldb configuration in which the database is in-process and it wants to store the data in local files?


[Jess in Action][AskingGoodQuestions]
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Well,

The situation was that I wanted to link back to the site where applet came from and use the hypersonic database driver to give some information from the table that is also on the same site.

I can use a Servlet for this purpose, and there are no problems with that Applet/Servlet communication. I want to learn to do the database access using applet only.
Here is my applet:


I am just trying to take output in the Java console.

Maybe you can help?

Thanks!

Maki Jav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
What does the "database" parameter look like? If it starts with "file:", then you're using in-process mode, which relies on access to the local file system.

You can create a memory-only database by using a "mem:" URL. But that will be empty upon creation, as there is no way to read table information and data from anywhere into it.

You could run HSQLDB in server mode on your server, and then connect to it over the network. This is all covered in the HSQLDB documentation.


Ping & DNS - updated with new look and Ping home screen widget
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

The page at the URL above uses a parameter like

<param name=database value="//users/adilj/test">

So this definitely looks like the driver wants to look at a local database. As Ulf says, check the manual on how to create a JDBC connection string for a remote server.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

Thank you Ulf and Ernest for your help. Sorry to reply late for I was ill. I have made following change in the web page



And now my Applet is giving this output in the Java console. This means that now it is trying to connect to the database...

http://www.myjavaserver.com/~adilj/
jdbc:hsqldb:http://www.myjavaserver.com/~adilj/htest
DataApplet java.sql.SQLException: Connection is broken

Maybe the database I created is not correct? What to do next?

Thank you.

ps: i used the following code to create database files locally and then upload it to myjavaserver.


[ December 16, 2007: Message edited by: Maki Jav ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
From my cursory reading of the documentation I doubt that HSQLDB can retrieve files through HTTP. Furthermore, how would it update them? Which part of the documentation gave you the idea this was possible?
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

I saw it here:

*http://hsqldb.sourceforge.net/doc/guide/ch04.html
http://hsqldb.org/web/hsqlDocsFrame.html

Maki Jav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
Connection URLs starting with "hsql" or "http" refer to the HSQLDB server modes, where there is an HSQLDB instance running permanently on the server. But from what you wrote is sounds as if that's not what you're doing.

One option might be to use the "res" connection URL scheme, and deploy the DB file in a jar file. It may even be possible not to put the DB file into a jar file, and just to have it in the same directory as the applet HTML file, but I"m not sure about that.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

Ulf I will try to do that, but the whole exercise is to get "hands on" experience of the database and applet connection using http.

Do you have a better database in your mind? so that I put the jar file of that database on myjavaserver and use it with my Applet?

Thank you,

Maki Jav
[ December 18, 2007: Message edited by: Maki Jav ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
You need to decide where you want to run the DB. Either it runs on the server as a standalone process, and can then be accessed through HTTP or some DB-specific protocol, or it runs as part of the applet (in which case there is no network access, HTTP or otherwise). Which of these is feasible in your case?

Both HSQLDB and Derby support both of these modes. What is not possible is to put the data and properties file of an HSQLDB DB on the server, and somehow expect the applet to be able to write to it.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Ulf,

I have used "res" mode and it has tried to connect with the myjavaserver resource. But unfortunately it did not find the table.
I have been trying to create the table and insert some data but looks like I failed!

Maki Jav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
I have used "res" mode and it has tried to connect with the myjavaserver resource. But unfortunately it did not find the table.

Which file did it try to access (that information should be in the server logs) - does it exist with proper permission where the applet is looking for it?

I have been trying to create the table and insert some data but looks like I failed!
"res" database connections are read-only, so you can't create tables or modify data.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

I am talking about creating tables on my computer locally. I have failed in doing that .
After I got the files created, I uploaded them on my server.
The code is given above for the class that is used to create hsqldb tables.
I am using this code:


The output from my applet ie Java console when the applet page is loaded is:

Applet code as reflected in Java console below...

String url="jdbc:hsqldb:"+getParameter("database");
System.out.println(getCodeBase() );
System.out.println(url);

----------------------------------------------------
http://www.myjavaserver.com/~adilj/

jdbc:hsqldb:res://www.myjavaserver.com/~adilj/htest

DataApplet java.sql.SQLException: Table not found in statement [select * from PROPTYPE]
[ December 22, 2007: Message edited by: Maki Jav ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
That's your problem:

st.execute("CREATE TABLE Property ("+
"TYPEID NUMERIC,"+
"TYPE VARCHAR);"
) );


st.execute("INSERT INTO PROPTYPE (TYPEID,TYPE)" VALUES ("2,"'BUNGLOW');");

I'm not sure that HSQLDB can alter tables loaded in this way, though, since there is no way to write the changes back to the file.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

How is this a problem?

I have used the

st.execute("CREATE TABLE Property ("+
"TYPEID NUMERIC,"+
"TYPE VARCHAR);");

with the same result. If I add System.out.println(.....); to the above, it is not causing any problem in compiling, but is is printing "false". It means that the table is not being created

Maki Jav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
Look closely at the SQL statements - you're creating a table called "Property", but you're trying to insert into a table called "PROPTYPE".

You can see what HSQLDB creates by inspecting the .script file that it creates. It contains the SQL statements needed to recreate the DB.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Ulf you are quite right.

But the problem is that I am not getting any exception and also I am not even able to create table "Property"


Maki Jav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
I am not even able to create table "Property"

Why not? What does the .script file look like?
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
http://www.myjavaserver.com/~adilj/htest.script

CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 20

Maki Jav
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

I had to pack the database files too along with the applet to make it work properly.

The final result on the Java console is:
------------------------------------
http://www.myjavaserver.com/~adilj/

jdbc:hsqldb:res:/htest/htest

2

BUNGLOW
-------------------------------------

I had to package database table etc

D:\java>d:\jdk1.4\bin\jar -cvf hdb.jar htest\*
added manifest
adding: htest/htest.lck(in = 16) (out= 18)(deflated -12%)
adding: htest/htest.log(in = 35) (out= 32)(deflated 8%)
adding: htest/htest.properties(in = 488) (out= 247)(deflated 49%)
adding: htest/htest.script(in = 152) (out= 123)(deflated 19%)

------------------------------------------------------------

Make these changes to the html Applet page That is add database jar file in archive lists in additon to HSQLDB driver jar file which I was already distributing on client. As driver file is big, it takes time but on next loading it works fast.

<HTML><HEAD></HEAD><BODY>
<APPLET CODE="DataApplet" CODEBASE="." WIDTH=400 HEIGHT=300
ARCHIVE="hsqldb.jar,hdb.jar">

<PARAM NAME = DATABASE VALUE = "res:/htest/htest" >

</APPLET>
</BODY></HTML>


-------------------------------------------------------


Maki Jav
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

I have modified and used a Type 3 driver which uses any other driver on the server locally for now with an applet

Maki Jav
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Same old problem?
 
Similar Threads
Objects, ArrayList and a Jsp but not Databases
free hosting for my chatServer
Running an exe file
HSQLDB Table
free hosting for my chatServer