• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enabled Web start in NetBeans, but lost database connection

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there messages in the Java Console?
 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I wrote many those handlers to deal with connectivity, if I understood question...

How is that attribute added?

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made this change:



But it doesn't work still...?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't matter what kind of server is serving the applet, the important thing is what machine it runs on.

http://localhost/phpmyadmin/index.php?db=mynewdata...


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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DB URL for applet is "jdbc:mysql://localhost:3306/MyNewDatabase". Is it ok?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be maybe easier for us to show you the code:


Where to put it? In catch parts?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try removing the extraneous opening brackets on lines 9 and 28, as well as whatever closing brackets go with them.
 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic