Connection with an excel document

Hi, I have a program that use a excel document as database, I get the data with the library JExcelAPI.

The application works fine, giving in the code the path of the document ("c:\book.xls"). When i use JWS i use the path "..//book.xls", but the program cant read from the excel, thats is located in the same directory of the proyect.

If the excel document is suppose to be in the server with the .jnlp file and the .jar of the program, What path i have to use?

[480 byte] By [Atreidea] at [2007-11-27 1:12:16]
# 1

> Hi, I have a program that use a excel document as

> database, I get the data with the library JExcelAPI.

>

> The application works fine, giving in the code the

> path of the document ("c:\book.xls").

This is a fragile way to build up a path to a file.

Note that if you create a String of that, and print it

out, it writes..

"cook.xls"

(if you do not believe me, try it!)

It is always best to use the ..

http://java.sun.com/javase/6/docs/api/java/io/File.html#File(java.io.File, java.lang.String)

..constructor to build up the path to the file.

>.. When i use JWS

> i use the path "..//book.xls",

And what is that supposed to mean?

>..but the program cant

> read from the excel, thats is located in the same

> directory of the proyect.

>

> If the excel document is suppose to be in the server

> with the .jnlp file and the .jar of the program, What

> path i have to use?

Never heard of JExcelAPI before today, but a bit of

googling and a lot of guesswork suggests that if

you get get a valid URL to the spreadsheet, you

might use..

http://java.sun.com/javase/6/docs/api/java/net/URL.html#openStream()

..to get an input stream, then provide that input

stream to..

http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/Workbook.html#getWorkbook(java.io.InputStream)

Message was edited by:

AndrewThompson64

AndrewThompson64a at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 2

Hi, thank you so much for the help but i have still problems.

I use the following code:

...

URL u= new URL("http://mywebpage.com/mydirectory/mybd.xls");

...

mybook = Workbook.getWorkbook(u.openStream());

...

Again it works fine if i execute the proyect from netbeans and directly from the .jar but when i execute the jnlp proyect, it dont read from the excel.

This is the jnlp:

<?xml version="1.0" encoding="utf-8"?>

<jnlp spec="1.0+"

codebase="http://localhost:8084/ProyectoJNLP/resources/" href="jnlp/prueba.jnlp">

<information>

<title>Grafica</title>

<vendor>Master</vendor>

<homepage href="http://www.unizar.es" />

<description>abc</description>

<description kind="short">abc</description>

<description kind="tooltip">abc</description>

<offline-allowed />

</information>

<resources>

<j2se version="1.4+" initial-heap-size="12m" max-heap-size="256m" />

<jar href="program/NubeDePuntos.jar" />

<jar href="program/lib/jcommon-1.0.6.jar"/>

<jar href="program/lib/jfreechart-1.0.3.jar"/>

<jar href="program/lib/swing-layout-1.0.jar"/>

</resources>

<application-desc main-class="Ventana" />

</jnlp>

Thanks for the help.

Atreidea at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 3

> Hi, thank you so much for the help but i have still

> problems.

...

> URL("http://mywebpage.com/mydirectory/mybd.xls");

...

> codebase="http://localhost:8084/ProyectoJNLP/resources/

Untrusted (sandboxed) web start apps. can 'phone home'

to the server that they came from, but not to other servers.

There are two ways to solve this:

1) Digitally sign the code and request all-permissions

in the JNLP file.

2) Put the JNLP launch file and the workbook

on the same server.

I guess the second is what you actually need.

Try putting a workbook on localhost and accessing

that.

By the way - it would help to get the exact ouput or

error message you are seeing - I am just guessing

what the problem is.

AndrewThompson64a at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 4

I dont get any error, the aplication has a few combos that are filled from the data of the excel, they just appear empty.

I use now this path for the excel archive, and still not working when i execute my web proyect:

u= new URL("http://localhost:8084/ProyectoJNLP/resources/jnlp/quimica.xls");

But, when i have the netbeans tomcat server running(after executing the proyect), If i execute the proyect of the .jar from netbeans the aplication reads the excel and works fine. If i double click the .jar of the jnlp proyect directly, it dont work.

Thank you for the help.

Atreidea at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 5

You mention you are note getting any errors.

What happens to exceptions that are thrown?

Does the code e.printStackTrace()?

Can you prepare a short example of

code that fails? It should be an SSCCE.

http://www.physci.org/codes/sscce.html

Do you have the Java console configured

to show the web start console every time

applications start?

AndrewThompson64a at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 6

Thanks, i open the console and get this exception:

java.net.MalformedURLException: no protocol: /jnlp/quimica.xls

at java.net.URL.<init>(Unknown Source)

at java.net.URL.<init>(Unknown Source)

at java.net.URL.<init>(Unknown Source)

at Modelo.abrirConexion(Modelo.java:25)

That line 25 is:

u= new URL("http://localhost:8084/ProyectoJNLP/resources/jnlp/quimica.xls");

Atreidea at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 7

Now i get this exception with the same URL:

Warning: Could not instantiate logger common.log.SimpleLogger using default

Warning: Error accessing system properties.

java.security.AccessControlException: access denied (java.util.PropertyPermission jxl.nowarnings read)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)

at java.lang.System.getProperty(Unknown Source)

at java.lang.Boolean.getBoolean(Unknown Source)

Atreidea at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 8
> java.security.AccessControlException: access denied (java.util.PropertyPermission jxl.nowarnings read)For some reason (beyond the source of the excel document) this code needs 'full permissions', seemy second reply about code signing.
AndrewThompson64a at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...
# 9
I have signed all the jars of the application and now it works fine.Thank you very much.
Atreidea at 2007-7-11 23:47:36 > top of Java-index,Desktop,Deploying...