Dear Forum:
Can connections to a database be made through an applet. If so does anyone
have a sample of this. Thanks in advance
Josh
Printable View
Dear Forum:
Can connections to a database be made through an applet. If so does anyone
have a sample of this. Thanks in advance
Josh
"Josh" <jbrandt@arastone.com> wrote:
>
>Dear Forum:
>
>Can connections to a database be made through an applet. If so does anyone
>have a sample of this. Thanks in advance
>
>Josh
Sure, but I don´t have any code to provide to you. But you can always import
the jdbc-driver specific classes to your Applet-code and connect to the database
through it. Applet security prevents your applet from connecting to another
host, than the one that provided the applet. You could of course make alterations
to your browsers security/authentication, or make a Remote Method Invocation
to another host, but the standard way is applet-host.
java.sql.Connection conn = DriverManager.getConnection("jdbc://"+host+"/"+db,
userName, passWord);
java.sql.PreparedStatement ps = conn.prepareStatement("SELECT custname, address
FROM customers WHERE custid = ? ");
ps.setInt(1, 45); // sets the value of custid
java.sql.ResultSet rs = ps.executeQuery();
if (rs.next()) {
System.out.println("Customer name: " + rs.getString(1));
System.out.println("Address: " + rs.getString(2));
}