File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Enabled Web start in NetBeans, but lost database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Enabled Web start in NetBeans, but lost database connection" Watch "Enabled Web start in NetBeans, but lost database connection" New topic
Author

Enabled Web start in NetBeans, but lost database connection

maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I'm having a problem: my applet made in NetBeans is connected to MySQL database using text field for input in applet. I enabled Web start to test applet on Web page, but now the database doesn't accept input from applet when I input from Web page. In Applet Viewer everything works just fine... Do you have any idea?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Are there messages in the Java Console?


Ping & DNS - my free Android networking tools app
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
No, there are no messages in Java console. Everything looks just fine, but there is no database recording... Is there any way to set path to the mysql driver in the html page? Who knows, that is maybe problem...?

This is the code of my page:



Are there any mistakes?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
The driver jar file needs to be listed in the archive attribute, along with your applet jar file.

It's odd that there's no error message in the Console, though - you don't have any empty try/catch handlers, do you?
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
Well, I wrote many those handlers to deal with connectivity, if I understood question...

How is that attribute added?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
You already have the attribute in the HTML you posted; it can contain several jar files separated by commas.

Your code should not have any empty catch blocks; you simply must handle -and not ignore- exceptions.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I made this change:



But it doesn't work still...?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Do you see any messages in the Console now (assuming you removed all empty catch blocks, and are printing error messages to System.err instead) ?
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
After this line:



I removed catch block and got this message:

Unpreported exception java.sql.SQLException. Local variable hides a field.

Build failed and I couldn't open the Web page.

Do you meant on this correction?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
I think it would help if you posted the complete stack trace (which you can get by putting ex.printStackTrace() into the catch block).
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I have just put it and I got this message while running the applet:

Note: C:\Documents and Settings\milica.neskovic\My Documents\Simulacija\AnimiraniAplet\src\org\me\test\Simulacija.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

When I run it in browser, it worked just fine, no error reporting, but it didn't make any insert to the database. I can update database only using Applet Viewer...
I don't understand this. What should I do?

I'm very grateful to you for interesting in my problems
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
That's a compile-time warning, not a runtime exception, so it doesn't make a difference.

One possibility why it's not working -although that would generate an error message in the Java Console, unless you still have empty catch blocks- is that the DB is not running on the same host from where you're running the applet. That would be prohibited for security reasons.

What URL shows in the browser when you run the applet - does it start with "file://" or "http://"? If the former, then it won't work. If the latter, does the DB run on the same machine that's in that URL?
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
It starts with "http://". About server: I think that is the problem, since I made MySQL database using XAMPP which has it's own built-in Web server - Apache. I display applet using Personal GlassFish v3 Domain, because it was offered by NetBeans. What should I do now? I wanted to change server in NetBeans, but it doesn't offer Apache as an option...

P.S. The database is run on this address http://localhost/phpmyadmin/index.php?db=mynewdatabase&token=6c1f4179ec45d6297b677fb817513fbb and applet on this http://localhost:15808/WebPrimer/newhtml.html, if it helps...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
It doesn't matter what kind of server is serving the applet, the important thing is what machine it runs on.


That's not a DB, that's a web GUI to a DB - does the DB run on localhost as well? If so, which DB URL is the applet using? It should have "localhost" in it.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
DB URL for applet is "jdbc:mysql://localhost:3306/MyNewDatabase". Is it ok?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
That should be OK. If there are really no messages in the Console -and you've made to sure to log all exceptions to System.out- then I suggest to put System.out.println statements in your code to find out what the actual flow of control at runtime is.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
It would be maybe easier for us to show you the code:


Where to put it? In catch parts?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Where to put it? In catch parts?

Everywhere - you need to find out which lines of code are or are not executed. I'd start by putting println statements at the start and end of each method.

public boolean action (Event evt, Object arg)

Oh boy. This way of handling events has been deprecated since around 1997. You really should be using event listeners instead, they apply to AWT as much as they do Swing: http://java.sun.com/docs/books/tutorial/uiswing/events/index.html
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I didn't know that, I'm sorry I will try to do as you said and I will tell what happened...
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I tried to make actionPerformed instead of action method and wrote this:



It returns error with "target" (line 27) saying that cannot find symbol. It is recognized in action method, but not here. Where did I make mistake? Is it good like this?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Try removing the extraneous opening brackets on lines 9 and 28, as well as whatever closing brackets go with them.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
I deleted, but nothing happens. It doesn't recognize this variable target in this method, only in action method... Can it be declared any way?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Ah, forgot about that - Event has a field called target, but ActionEvent doesn't (it doesn't extend Event). Check its javadocs for what the corresponding field is called, or the tutorial I pointed you to.
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
One friend told me that problem might be that client application can't work nothing on web server, nor to write in database. He mentioned something about server script. Can it be a solution and, if can, how to make it?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
An applet can connect to a DB that's running on the same server where the applet was served from; if the DB is on some other server, then the applet can't connect to it (unless it is signed, but I suggest we leave out that possibility for now).

A workaround to this security restriction is to have the applet connect to an active server-side component on the server where the applet was served from (this would act as a proxy server, and could be a servlet, or PHP script, or some such - probably what your friend referred to as "server script"). This server-side code would then access the DB (which could be on any server, since the code wouldn't be subject to security restrictions).

This is a whole different kind of setup and programming environment (and learning curve) than applets - are you prepared for that? If so, start reading up on servlets or PHP or some such technology, and -if you have questions about it- start a new topic in an appropriate forum. (In other words, not in this Applet forum right here).
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
When I made connection and run the applet on Web page, an error occurred requesting to sign in applet. I activated the Web start in the NetBeans and solved that I thought that I had made it, but then I realised this problem with connection... which I can't solve I'll look something about servlets. Thank you, Ulf, for interesting.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Just be aware that injecting a server-side proxy makes this project a LOT more complicated, especially if you have no experience with server-side processing. If this was my problem I'd first spend more time investigating why the applet approach that should work, doesn't.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enabled Web start in NetBeans, but lost database connection