• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applets and jdbc

 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i intend on using a java applet in conjuction with a mySql databse using jdbc. Before i throw myself into it, can this be done?
and if so is there anything i should watch out for?
or additionally need to install or download?
best regards,
zack,
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can do this, but it wont be very helpful. Because when someone over the internet tries to use your applet, the applet will try to find the database file in that "someone's" computer, and of course it wont be existing there. So I suggest that you use a servlet or a ServerSocket at the server side which communicates with the client i.e. your applet.
 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks sharshank.
i am however after doing a bit of homework on the applet idea in the mean time and have found that if a policy file and a signed applet were used together the database could be accessible remotely ie the client. would you agree with going with this idea as i have already written the applet? if not how great would be the transition from applet to servlet?
thanks again for your patience.
z
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi zack,
Its great if you've found another way to connect to a remote host. I'll encourage you to go ahead with your discovery, this will give you a sense of satisfaction ('coz u would have done it "your way") and it would also save you time. Well, i've not used the idea that you have used, so it would be unfair of me to comment as to which of the ideas is better. Well all the best with your idea.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zack,

Personally I wouldn't recommend connecting to a database directly from your applet. That solution doesn't scale well and it's also awkward to manage database connections created client-side.

I don't really see how a servlet (an HTTP one at least) would help here. What you would need, however, is a server component to manage the database connections. Your applet would connect to this server, which would connect to the database. You could use a java.net.ServerSocket to implement this.

It all depends how serious your application is. If it's just a "get to know Java" exercise then it's probably best keep it simple; you can always change the architecture once you've got it working.

I hope that helps.

Jules
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zack, it's really not that big of a deal to access a database from an applet. The only catches are that they database has to be on the same server you are delivering tha applet from and your applet has to be signed.

I did this for an intranet app where I work a couple of years ago. I posted my instructions for getting it going here.

Hope that helps.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zack,

If you do choose to connect to the database directly from your applet here are a couple of points to consider:
  • Opening a new connection each time you need to access the database adds a tangible overhead.
  • Holding a database connection open to eliminate this overhead can leave active sessions on the database server if the client doesn't close down in a controlled manner or you're not careful how you close connections.


  • Either close your connections in a finally clause and, probably, in the applet's destroy() and/or stop() methods (option 2) or ensure that your connections are open for the shortest possbile time (option 1).

    Jules

    P.S. Gregg, how do you get the font size for the code block to come out so small?
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Julian Kennedy:

    P.S. Gregg, how do you get the font size for the code block to come out so small?


    I have no idea. Sometimes that happens, and sometimes it doesn't.
     
    zack chancery
    Ranch Hand
    Posts: 33
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks to everyone that replied. I have yet to come across such an organised and easy-to-use help site as this. no doubt i will be back!
    cheers guys,
    z
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic