-
Applets
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
-
Re: Applets
"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));
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks