Results 1 to 15 of 15
  1. #1
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default MySQL application to applet?

    Hello!

    I have an application that uses gui to communicate with the MySQL database.
    It is a typical 4000 lines of code application that I was developing in NetBeans.
    It does work ok and the way I wanted it to.

    But heres the fun part. Somehow someone managed to get the idea that it would be a lot better if the application would run on a server so everyone can access it from a web browser. (which I told them would be better in the fors place.. but no..application is just as good).

    Of course it is a lot better to have an application that 1000 people use to store measurments is better with a unified database that everyone can access by simply typing in an address in the browser.

    So I tell this to my professor at school because I thought that the best way to do that would be by simply changing it to an applet.
    Then he said: "the last time I did an applet with a database access directly was 10 years ago" so he cant help I guess because somehow applets using JDBC driver kinda dont wanna show up in browsers due to multiple errors in not being able to find classes (even when specifying the archive) and other errors as well and so on ..

    So My question:
    What options do I have at changing a NetBeans application with MySQL to a over web application without having to create the GUI from nothing again (which took 20 hours) and writting half of the code again?

    (Other options that disclude applets are also welcome?)

    CS Natrix

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Natrix View Post
    So My question:
    What options do I have at changing a NetBeans application with MySQL to a over web application without having to create the GUI from nothing again (which took 20 hours) and writting half of the code again?
    What is a NetBeans application? NetBeans is an IDE which is used to create Java code, so saying that you have a NetBeans application is only telling us that you have a Java application. Is this a Swing application that you've created using NetBeans-generated Swing code, is this what you mean?

  3. #3
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Yes, that is what I mean. =)

    Please do understand that I could be unable to specificly clarify what I want since english is not my native language. So I dont really know exactly how you interpret what I write.

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    I think you have just learned why the MVC (Model/View/Controller) development pattern is so strongly encouraged. If you rigorously follow MVC practices, then when you find yourself in your current situation, you need only write a new View, and not re-engineer the entire app.

    If your current app does not follow the MVC pattern, then this will be a good opportunity to learn by re-implementing the app as MVC. The bad news is that it will of course be a lot of work. The good news is that a working prototype (which you have) is often the best specification for a development project, and typically the specification process is the hardest part. Good luck!

    -Gary-

  5. #5
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Hm.
    I wonder why I never heard of that and why wouldnt the professor tell me that?

    Ok, thats one option.
    Is there something I can do by not having to do 50% of the work all over again or is that all I have?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Natrix View Post
    Hm.
    I wonder why I never heard of that and why wouldnt the professor tell me that?

    Ok, thats one option.
    Is there something I can do by not having to do 50% of the work all over again or is that all I have?
    My fear is that because you've let NetBeans generate your code, your main class subclasses either JFrame or SomethingApplication. If this is so, it may be harder to make the changes you wish. If on the other hand your Swing code is geared to making JPanels, it will be easier.

    Having said that, one possible quick and dirty fix would be to create your JFrame/application object, get its contentPane via getContentPane() and place that into a JApplet.

  7. #7
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Well, it depends on the code you currently have, how it's structured, what your classes are, how they fit together, etc. Without seeing your current code, it's impossible to say how much of it can survive unchanged. If I had to guess, I'd say you'll end up re-writing most of it.

    But this is not a terrible thing, really. First of all, every experienced programmer has been through this, and that's how we learn. Re-writing from a working model is not the same as writing from scratch. You'll do a lot of it better than you did the first time, and your overall design will be clearer. It won't take as long, and you'll be happier with the result. And you'll start to understand why your professor encouraged you to write good documentation while you are writing your code.

    -Gary-

  8. #8
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    I have already fully transferred the GUI to an applet.
    (NetBeans has a list of GUI components so you just copy them into a Applet or JApplet form)

    The applet however works great in appletViewer but not in browser.


    This could be due to security reasons ( not letting the applet access the database directly). But I am not sure why wouldnt that be possible..

    Even with a simple applet using a simple SQL query over a JDBC driver doesnt work in browsers. Only in appletViewer..

    -----
    Thank you Gary.
    I also think that I will end up re-writting it. I wanted to ask what else I can, If I can do anything at all to save precious time.. :)
    Last edited by Natrix; 03-27-2010 at 09:57 PM. Reason: Respond to Gary

  9. #9
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    I think you will want to take a step back and think about the overall architecture. Should each instance be communicating directly with the MySQL database, or should they be going through some other server layer (SOAP, RMI, XML-RPC, etc.)? Is Applet really the right way to go, or would Java Web Start be a better fit? Or Google Web Toolkit? Or some other AJAX implementation? What access controls and security will you need? Try not to think in terms of preserving the maximum existing code. Think instead about "how would I design this now, knowing what I know now that I didn't know the first time?"

    The first attempt was not a waste. You learned a lot about the problem, and you are now in a much better position to address it.

    -Gary-

  10. #10
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Well another problem is that Ive had two years of java in school.
    We did nothing but basic applications.
    So other than applets and applications I have no experience and only 14 days (lets say 30 hours of available actual time because of other school stuff) to finnish it.

    (one plus however is that the thing I get points for can remain an application and the real project which will be actualy used can be a whole different project, althought I told the president of our association that it could be done by end of april, not knowing that I will have to totaly change everything)
    Last edited by Natrix; 03-27-2010 at 10:31 PM. Reason: fixed second sentance

  11. #11
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    I guess this is the best thing to do?

    http://java.sun.com/developer/techni...intro.anc3.jpg

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I especially like the "or other calls" statement. :)

  13. #13
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Haha why is that so?

    We did an application that prints out the HTML source using HTTP GET.. it really doesnt work well.. unfortunately.
    Is that what is ment with the calls?

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Natrix View Post
    Haha why is that so?

    We did an application that prints out the HTML source using HTTP GET.. it really doesnt work well.. unfortunately.
    Is that what is ment with the calls?
    To me it means: this layer can be implemented in many, many different ways, too many to list here, describe, or rate.

  15. #15
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    You might start by tweaking your existing Application into a Model/View/Controller design. The Model is anything about your app that represents something in the real world. So for instance, if it's an order entry application, then the Model consists of the Order class, the OrderLineItem class, the Customer class, the InventoryItem class and so on. The View is of course your GUI, and the Controller is the central point of dispatch for all of your app's processing. The View always talks to the Controller -- never directly to any class in the Model. The Controller creates objects from the Model and calls their methods and keeps everything up-to-date. The Controller also talks to the database.

    The set of methods you implement in your Controller class for the View to call will be the key design elements of your application. If you design those well, it will be pretty straightforward to implement a network layer between the Controller and a View.

    -Gary-

Similar Threads

  1. Need to help to create an application using jsp, web services, ejb, mysql
    By sankethm7 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 04-22-2009, 11:06 AM
  2. Creating Java EE application with MySQL db
    By [RTS]BN+VS* in forum JDBC
    Replies: 0
    Last Post: 03-25-2009, 02:46 PM
  3. Making an Applet use a MySQL Database
    By Bomber_Will in forum Java Applets
    Replies: 5
    Last Post: 11-30-2008, 05:28 PM
  4. Connect applet with mysql
    By baltimore in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 07:39 AM
  5. Connect applet with mysql
    By Felissa in forum Java Applets
    Replies: 3
    Last Post: 07-05-2007, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •