• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Database Applet

 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I'm a long time Delphi / Mumps programmer for about 7 years. I've used Visual Basic off and on during that time as well. I've been asked to develop a web page for billing purposes. Everything is working perfectly, and I've added in a lot of javascripting to validate my form fields.
Now, I'd like to add in some additional functionality that VERIFIES the actual data (not just the fields) before I submit the data in the form to the billing center.

My question is not about Javascript, but about a Java Applet.

I've barely used any Java at all. I can program in C++ though so I've got the syntax down and I understand the concept of Java enough that I should be able to pick it up easily enough. (Or so I hope).

I was wondering if anyone had an example of a Java Applet that allows me to access a database from the server. My question however is, does the Applet run on the computer of the person who's accessing the web page, or on the server that is hosting the web page?

Basically, I'd like to write a Java Applet that will allow me to submit queries to a database that's local to the host.

Does anyone have any examples of an applet such as this, or can anyone give a newbie any advice?

I have used Eclipse 3.0 as my Java developer before, but like I said my experience with it was rather limited.

Any help would be appreciated.

Any examples would REALLY be appreicated!!!



Thanks!!!

Todd
 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For anyone following this thread and / or interested in the answer, I did find one example on the internet:

http://www.shiningstar.net/geek/html/javadbf.html

I hope that helps some of you.


If anyone has anything else to add, PLEASE feel free to add anything. I have yet to try this, so I don't even know if it will really work for me.


Thanks!

Todd
 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have an example of how I would convert this to perhaps an SQL database?


Thanks!

Todd
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your not getting many bites yet, so I'll add something until the others arrive.
An applet runs in the browser on the client machine.
It can communicate with the server via URLConnection or Socket or ...
Your applet would build a URL, pass it to the server and read the response.

You said one thing that I'm not sure of:

database that's local to the host.


Does this mean that the applet and browser and database are all on the same machine and that there is no connection to the internet and no server?
Which is the host: server or client?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the DB is local, the applet needs to be signed, otherwise it won't have access to local resources. I'd recommend using the standard JDBC classes (java.sql.*) for DB access, because then you only need to change the driver, URL, username and password parameters. The example seems to use some non-standard DB access methods, though, which are not as portable as JDBC. SQLServer drivers are available from Microsoft; you'll also find example code of how to use them there. Let us know if you get stuck somewhere.
 
David M Fairchild
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Todd,

I'm doing, practically the same thing. I have experience with ASP so I set up a web site to use ASP (it's Windows IIS so pretty easy to do). Then I have my Java Applet send requests back to my web site for data.

To encapsulate every thing I created a class, 'WebData', which knows how to connect to the web site and can build a request. Here is the code for that:

import java.io.* ;
import java.net.* ;
import java.util.*;

public class WebData {
HttpURLConnection con;
String cb;

/**
* Method WebData
*/
public WebData(String codeBase) {
cb = codeBase;
}

public Vector<String> getData(Vector<String> params) {
Vector<String> aList = new Vector<String>();
URL textURL;
String line;

String command = cb + "getData.asp?";
for(int i=0;i<params.size();i++) {
command = command.concat(params.get(i) + "&");
}
command = command.substring(0, command.length() - 1);

try {
textURL = new URL(command);
BufferedReader theStream = new BufferedReader(
new InputStreamReader(textURL.openStream()));
// now read the lines one at a time
while ( ( line = theStream.readLine() ) != null ) {
aList.add(line);
} // close while loop

theStream.close();

} catch(Exception e) {
System.out.println(e.getMessage());
}

return(aList);
}
}

Because this is an applet, it's simplier to connect back to the web site that sent the applet. The function 'getData()' takes a Vector of string consisting of the name of the function (on the ASP file) that I want to call and any parameters that are necessary to call that function. It returns a Vector of String.

In my application, the list boxes and combo boxes have an instance of the WebData class and know how to display the Vector of String they get back from the getData() function. So the Vector to call the data just gets passed thru them as such:

public void listJobCodes() {
Vector<String> params = new Vector<String>();
int i = WorkGroups.getSelectedIndex();

if(i < 0) {
i=0;
}

params.add("getJobCodes");
params.add((String)WorkGroups.getKey(i));

JobCodes.getData(params);
}

This method tells the JobCodes list to get the job codes associated with a specific WorkGroup that the user selected. You can see where it builds the parameters that will be sent to WebData. The function 'getJobCodes' is coded in the asp file on the web server.

This could be done with jsp, perl, php or any cgi application.

Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic