|
Re: How can i connect an applet with a database????
|
Posted: Sep 10, 2004 5:16 PM
|
|
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
|
|