 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mark A Framness Guest
|
Posted: Fri Feb 13, 2004 5:36 pm Post subject: mySQL JDBC & Applet problem |
|
|
Greetings,
I have a simple applet which access a mySQL database via JDBC. On my
local machine and via Netscape it works however on netscapes from over
the I'net and Konqueror on my local machine it does not.
I have altered my hosts file and my Apache config file to point at my
dialup's IP.
Here is the Java console output from Konqueror which is similar to
what Netscape gives when run on a remote machine.:
============================================================
Java VM version: 1.4.2_03
Java VM vendor: Sun Microsystems Inc.
Exception thrown registering driver!
access denied (java.lang.RuntimePermission getClassLoader)
Exception thrown trying to query!
No suitable driver
============================================================
Here is the java code:
========================================
import java.sql.*;
import java.awt.*;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
public class dbApplet extends java.applet.Applet
{
public void paint(Graphics g)
{
try
{
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex)
{
System.out.println("Exception thrown registering driver!");
System.out.println(ex.getMessage());
// handle the error
}
try
{
int x = 10;
int y = 10;
Connection conn =
DriverManager.getConnection("jdbc:mysql://[CURRENT_DIALUP_ID or
127.0.0.1]:3306/HOMETITLE_D?user=generic&password=pword");
Statement sttmnt = null;
ResultSet rs = null;
sttmnt = conn.createStatement();
rs = sttmnt.executeQuery("Select emp_fname from employees");
setBackground(Color.black);
setForeground(Color.yellow);
while(rs.next())
{
g.drawString(rs.getString(1), x, y);
y += 10;
}
} catch(Exception e)
{
System.out.println("Exception thrown trying to query!");
System.out.println(e.getMessage());
}
}
}
=====================================================================
Thanks
|
|
| Back to top |
|
 |
Silvio Bierman Guest
|
Posted: Sun Feb 15, 2004 11:45 pm Post subject: Re: mySQL JDBC & Applet problem |
|
|
"Mark A Framness" <farmer (AT) netnet (DOT) net> wrote
| Quote: | Greetings,
I have a simple applet which access a mySQL database via JDBC. On my
local machine and via Netscape it works however on netscapes from over
the I'net and Konqueror on my local machine it does not.
I have altered my hosts file and my Apache config file to point at my
dialup's IP.
Here is the Java console output from Konqueror which is similar to
what Netscape gives when run on a remote machine.:
============================================================
Java VM version: 1.4.2_03
Java VM vendor: Sun Microsystems Inc.
Exception thrown registering driver!
access denied (java.lang.RuntimePermission getClassLoader)
Exception thrown trying to query!
No suitable driver
============================================================
Here is the java code:
========================================
import java.sql.*;
import java.awt.*;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
public class dbApplet extends java.applet.Applet
{
public void paint(Graphics g)
{
try
{
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex)
{
System.out.println("Exception thrown registering driver!");
System.out.println(ex.getMessage());
// handle the error
}
try
{
int x = 10;
int y = 10;
Connection conn =
DriverManager.getConnection("jdbc:mysql://[CURRENT_DIALUP_ID or
127.0.0.1]:3306/HOMETITLE_D?user=generic&password=pword");
Statement sttmnt = null;
ResultSet rs = null;
sttmnt = conn.createStatement();
rs = sttmnt.executeQuery("Select emp_fname from employees");
setBackground(Color.black);
setForeground(Color.yellow);
while(rs.next())
{
g.drawString(rs.getString(1), x, y);
y += 10;
}
} catch(Exception e)
{
System.out.println("Exception thrown trying to query!");
System.out.println(e.getMessage());
}
}
}
=====================================================================
Thanks
|
Applets run in a very restricted environment where many operations are
prohibited. Access to the local filesystem or hardware (ports etc), network
communication with any other host (including localhost) than the one that
served the HTML page etc. are not allowed. JDBC access will thus only work
if the webserver is also the database server.
It may work on your own computer because you have altered the permission
settings for applets in your JRE but in general you will be in trouble.
Signing the applet is an option but this requires an expensive certificate
issued by the likes of Verisign.
Applets are troublesome for most applications. The functionality you seem to
want can much better be reached through a HTML based UI. You should consider
applets only if other alternatives fail.
Silvio Bierman
|
|
| Back to top |
|
 |
Mark A Framness Guest
|
Posted: Mon Feb 16, 2004 3:56 pm Post subject: Re: mySQL JDBC & Applet problem |
|
|
"Silvio Bierman" <sbierman (AT) idfix (DOT) nl> wrote
| Quote: | "Mark A Framness" <farmer (AT) netnet (DOT) net> wrote in message
news:8168768c.0402130936.16b4cd9e (AT) posting (DOT) google.com...
Greetings,
I have a simple applet which access a mySQL database via JDBC. On my
local machine and via Netscape it works however on netscapes from over
the I'net and Konqueror on my local machine it does not.
|
| Quote: | It may work on your own computer because you have altered the permission
settings for applets in your JRE but in general you will be in trouble.
Signing the applet is an option but this requires an expensive certificate
issued by the likes of Verisign.
Applets are troublesome for most applications. The functionality you seem to
want can much better be reached through a HTML based UI. You should consider
applets only if other alternatives fail.
|
Thanks Silvio,
From the research I have been doing it appears this is what mod_jserv,
tomcat, Jakarta & J2EE is all about, correct? The consulting company I
work for is keen on having us learn Java and I am trying to find a way
to work Java into this.
I suppose I can have a applet front end which does some basic editing
and data validation and then have the data passed off to a servlet on
the server side which then performs the required updates, correct? I
am running apache 2.0.48. I guess I need mod_jserv or tomcat. What are
the pros & cons of each? Do I need an app server such as J2EE or
WEbsphere and either way is there a good open source alternative to
J2EE or Websphere?
Thank You
|
|
| Back to top |
|
 |
Silvio Bierman Guest
|
Posted: Wed Feb 18, 2004 12:23 am Post subject: Re: mySQL JDBC & Applet problem |
|
|
"Mark A Framness" <farmer (AT) netnet (DOT) net> wrote
You are very welcome
| Quote: |
From the research I have been doing it appears this is what mod_jserv,
tomcat, Jakarta & J2EE is all about, correct? The consulting company I
work for is keen on having us learn Java and I am trying to find a way
to work Java into this.
|
For good reasons, I would think. Java is great for this kind of stuff. You
could indeed use Tomcat and servlets for this. You can do without
mod-jserv/apache if all you need is a servlet container that can also serve
as a plain HTTP server. If you go big-load with static content you should
consider linking with apache though.
| Quote: |
I suppose I can have a applet front end which does some basic editing
and data validation and then have the data passed off to a servlet on
the server side which then performs the required updates, correct? I
am running apache 2.0.48. I guess I need mod_jserv or tomcat. What are
the pros & cons of each? Do I need an app server such as J2EE or
WEbsphere and either way is there a good open source alternative to
J2EE or Websphere?
Thank You
|
As i said you can do it all with Tomcat and j2se. Apache/mod_jk is fine for
serving heaps of static content beside the servlets content. J2ee would only
come in when you want EJB functionality. In that case you should look at
JBoss, which is a free EJB container.
Talking about JBoss, it stacks onto a servlet-container like Tomcat but
defaults to Jetty. That is a very fine (in my opinion superiour to Tomcat)
servlet container that is also free and has splendid and prompt support
through the mailing-lists. Check out http://www.mortbay.org for more info on
Jetty.
As a last not: you could indeed run an applet is the GUI and do
applet/servlet communication for the backend/database/bl etc. stuff. This is
a far better approach than doing to much on the applet side. I would however
still suggest that you look into servlet-generated HTML as the user
interface. Applets have more disadvantages as what I already mentioned, the
biggest being the absence of Java in all recent IE versions. You would
severely limit your user potential because they would have to donwload and
install a JRE first.
Regards,
Silvio Bierman
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|