The Artima Developer Community
Sponsored Link

Java Answers Forum
How can i connect an applet with a database????

3 replies on 1 page. Most recent reply: Sep 22, 2004 12:20 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Periklis

Posts: 5
Nickname: panpol2
Registered: Sep, 2004

How can i connect an applet with a database???? Posted: Sep 9, 2004 5:51 AM
Reply to this message Reply
Advertisement
I want to connect my applet with PostgreSQL and i dont know how.Can anyone please help me?

Thanks..


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: How can i connect an applet with a database???? Posted: Sep 10, 2004 5:16 PM
Reply to this message Reply

try{
/** Load Driver **/
Class.fornName("SomeDiriver.in_some_directory.Class");
/** Obviously you don't actually type in:
** Class Object associated with the String
** SomeDriver.in_some_location
** E.g. sun.jdbc.odbc.JdbcOdbcDriver
**/
}catch(ClassNotFoundException e){
System.out.println("Class not found");
System.exit(1);
}
Connection conn = DriverManager.getConnection ("the_server.that_I_am_connecting.to","user", "password");
String createString = "CREATE TABLE MyTable(field VARCHAR(35),....)
stmt.executeUpdate(createString);
stmt.executeUpdate("NEW SQL COMMAND...");

/** Remember to throw SQLException, IOException **/

You might want to have this method in a separate class
with various setter methods. E.g.
DBClass mydatabase = new DBClass("However you want
your Constructor Setup");
mydatabase.connect("my_database.here.com", user, passwd);
mydatabase.put("Probably An SQL Command");




Obviously that means you write a new class - DBClass
That handles your interactions between your applet
fields and your DataBase.

Hey good luck man...

Spike

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: How can i connect an applet with a database???? Posted: Sep 22, 2004 11:59 AM
Reply to this message Reply
Sorry I kind of misled you. An Applet cannot
access the local file system. I was unaware
of this my badd... However, apparently you
may use JarSigner to give your Jar file certain
access priviledges...

Check out:

http://java.sun.com/docs/books/tutorial/jar/sign/signing.html

Sorry again... Right now, I'm playing around with
something similar, I'll tell you how that works out...

One,
Spike

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: How can i connect an applet with a database???? Posted: Sep 22, 2004 12:20 PM
Reply to this message Reply
Another way to do it on the local machine
(just to see if your applet will work before
you start twidling with other settings),
you could look for the java.policy file

Found in: SomeDirectory\jdk\jre\lib\security

Atleast that's the structure on my machine,
and include the following line after

grant{

permission java.security.AllPermission;

This is if JDBC and your applet are all running
locally. Your applet should show up. Worked
for me, else, there is beef with your code...

Hope that rectifies the lies I told...

One,
Spike

Flat View: This topic has 3 replies on 1 page
Topic: Constructor Previous Topic   Next Topic Topic: Integrated Development Environment (IDE) Usability Survey

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use