CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    2

    Java and Databases - on the web

    Hi,

    I am currently working on a Java application, which is to be published on the web, that needs to get data out of a database. It does not need to make any new entries to the database, it only needs to access it. The people that will use this application will be complete novices, and will have nothing more than a Browser with a Java RE. It's got to be something that will work for them, instantly, without them having to change their classpaths.

    My initial plan here was to make a java applet, and have it connect to a mySQL server - something I did years ago, on a local machine.

    I've found various tutorials explaining how to do this, but all of them include a step where I've got to put the mySQL driver into my machine's classpath. I could do this, of course, but would every user wanting to use my applet have to do the same thing to get it to work?

    If so, can someone suggest an alternative approach? Java Web Start, different type of database? Settings I could ask the server's administrator to change for me?

    Whatever I do, it's got to be something that'll be good to go for someone browsing to my site.

    Thanks in Advance & forgive me if these questions are based on me not quite getting how SQL Drivers and stuff like that even work.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Java and Databases - on the web

    Java Web Start will give you a full Java client application, so you could directly access any database you like.

    Alternatively, you could use a tiered client-server approach, with a server-side facility (a servlet or web service, etc) to query the database on behalf of the client and return the data to the client in a convenient format, e.g. XML. This approach is more flexible than the direct Java Web Start approach as it allows you to use both pure Java clients (including JWS) and browser-based clients.

    Any programming problem can be solved by adding a level of indirection...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    May 2009
    Posts
    2

    Re: Java and Databases - on the web

    Hi,
    I tried the second approach you suggested, using PHP as a proxy. Works quite well when I'm only dealing with standard English characters, Unicode characters come out like this, though:

    "пӧрт"

    So I'm guessing something is off with my Character encodings. The Java code for the section where I get my data from the PHP site is:

    Code:
    String goTo = "http://[...]/info.php?search=" + search;
    
    URL page = new URL(goTo);
    URLConnection con = page.openConnection();
    DataInputStream dis = new DataInputStream(con.getInputStream());
    String inputLine;
    
    while ((inputLine = dis.readLine()) != null) {
    	giveout += inputLine;
    }
    dis.close();
    The content on my proxy page, in one example, would be:

    Code:
    пӧрт|house; hut; room, chamber; home|no|¤|¤
    I have not had any problems with Unicode characters elsewhere in my Java code, so I assume I need to:

    * set the encoding for my connection to Unicode, somehow
    * mark my php page as Unicode, somehow

    (I've tried the latter, but all that gets me is an extra line read in by my java applet, telling me that the character encoding is UTF-8, but not actually changing anything)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured