Hi all,
I created a Java application which allows me to send information to my mysql database using the jdbc connector via a JFrame. However when i modified the file to be a JApplet the info will not sent and i cannot connect to the database? Any particular reason for this?
I need it to be a JApplet so i can add it to a browser window.
[code=java]
private void save ()
{
Connection conn = null;
try
{
Statement stmt;
String userName = "root";
String password = "PASSWORD";
String url = "jdbc:mysql ://localhost:3306/DATABASE";
Class.forName ("com.mysql.jdb c.Driver").newI nstance ();
conn = DriverManager.g etConnection (url, userName, password);
System.out.prin tln ("Database connection established");
//Get a statement object
stmt = conn.createStat ement();
stmt.executeUpd ate( "INSERT INTO TABLE(Info i know to put in) VALUES('Values i know to put in')");
}
catch (Exception e)
{
System.err.prin tln ("Cannot connect to database server");
}
finally
{if (conn != null)
{try
{conn.close ();
System.out.prin tln ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors*/ }
}
}
}
[/code]
As i said above it works as a JFrame but not as a JApplet. Any help would be great.
Thanks G.
I created a Java application which allows me to send information to my mysql database using the jdbc connector via a JFrame. However when i modified the file to be a JApplet the info will not sent and i cannot connect to the database? Any particular reason for this?
I need it to be a JApplet so i can add it to a browser window.
[code=java]
private void save ()
{
Connection conn = null;
try
{
Statement stmt;
String userName = "root";
String password = "PASSWORD";
String url = "jdbc:mysql ://localhost:3306/DATABASE";
Class.forName ("com.mysql.jdb c.Driver").newI nstance ();
conn = DriverManager.g etConnection (url, userName, password);
System.out.prin tln ("Database connection established");
//Get a statement object
stmt = conn.createStat ement();
stmt.executeUpd ate( "INSERT INTO TABLE(Info i know to put in) VALUES('Values i know to put in')");
}
catch (Exception e)
{
System.err.prin tln ("Cannot connect to database server");
}
finally
{if (conn != null)
{try
{conn.close ();
System.out.prin tln ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors*/ }
}
}
}
[/code]
As i said above it works as a JFrame but not as a JApplet. Any help would be great.
Thanks G.
Comment