Results 1 to 5 of 5
- 05-17-2010, 11:34 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Applet runs on Web page, but no database connection
My applet made in NetBeans is connected to MySQL database using text field for input in applet and button to confirm input. I enabled Web start in order to show applet on Web page and test it, but now the database doesn't accept input from applet when I input from Web page. In Applet Viewer everything works just fine... Do you have any idea?
I have isolated this code which is related to the problem:
Java Code:package org.me.now; import java.awt.*; import java.applet.Applet; import java.awt.Event; import java.sql.*; import java.net.SocketPermission; public class New extends Applet implements Runnable { FlowLayout lm = new FlowLayout(FlowLayout.RIGHT); Button open; Connection con; private String upit, url, baza; private Statement stmt; private ResultSet rezultat; TextField plaintext = new TextField(20); Label plaintextvalue = new Label(); @Override public void init() { setBackground(new Color(60,179,113 )); try { Class.forName("com.mysql.jdbc.Driver"); String url1 = "jdbc:mysql://localhost:3306/MyNewDatabase"; con = DriverManager.getConnection(url1, "root", ""); Statement stmt1 = con.createStatement(); ResultSet rezultat1 = stmt1.executeQuery("select * from evidencija"); } catch(Exception e) { e.printStackTrace(); } add(new Label("Unesite ime i prezime radi evidencije posete")); add(plaintext); add(new Button("Potvrdite unos")); add(plaintextvalue); } public void Close(java.sql.Statement stmt) { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } @Override public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) { String labl = (String) arg; if (labl.equals("Potvrdite unos")) { plaintextvalue.setText (plaintext.getText()); try { Statement stmt2 = con.createStatement(); String updateString = "INSERT INTO evidencija (ime)" + "VALUES ('"+plaintext.getText().toString()+"')"; int count = stmt2.executeUpdate(updateString); } catch (Exception e){ e.printStackTrace(); } finally { } } {if (evt.target == plaintext) { plaintextvalue.setText (plaintext.getText()); return true; } } } return true; } @Override public void paint(Graphics g) { } void checkWebPermission() { final SecurityManager sm = System.getSecurityManager(); if (null == sm) throw new RuntimeException("Security manager is null"); sm.checkPermission(new SocketPermission("www.google.com", "connect")); System.out.println("Got permission to connect."); } @Override public void start() { } @Override public synchronized void stop() { } @SuppressWarnings("static-access") public void run() { } }
- 05-17-2010, 03:30 PM #2
Do you get any error messages?
What server and browser are you using?
Is this being executed inside of Netbeans or outside?
- 05-17-2010, 03:37 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
I don't get error messages. I'm using XAMPP as local server. My default browser is IE. I run it inside the Netbeans.
One friend told me that problem might be that client application can't work nothing on web server, nor to write in database.
I'm reading about servlets now. Can it be solution for this problem?
- 05-17-2010, 05:40 PM #4
The error messages would be in the browser's java console Probably something about not having permission.
- 05-19-2010, 04:46 AM #5
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
the problem is actually may cause the applet location... A non native host applet cannot access Database unless it's signed.
The code is really hard one as for any browser
To make it work I recommend use applet<->servlet bound. Place the hard code to servlet and it should work fine. And do the applet as an invoker...Java Code:try { Class.forName("com.mysql.jdbc.Driver"); String url1 = "jdbc:mysql://localhost:3306/MyNewDatabase"; con = DriverManager.getConnection(url1, "root", ""); Statement stmt1 = con.createStatement(); ResultSet rezultat1 = stmt1.executeQuery("select * from evidencija"); }
The second thing is to sign your applet but it is no good because as a rule signing means not its native server correct connection but a client local file system access wanted... It doesn't worth the effort as for db connection...If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
Similar Threads
-
connection to database
By buston01 in forum JDBCReplies: 4Last Post: 02-21-2010, 01:32 AM -
getting database connection
By ravidasineni in forum AWT / SwingReplies: 1Last Post: 11-22-2009, 02:01 AM -
Database connection for applet
By danielsl89 in forum Java AppletsReplies: 2Last Post: 10-21-2009, 12:24 PM -
Applet Errors runs in jGrasp/ not in Eclipse and not in browser
By Wallsurfer in forum Java AppletsReplies: 10Last Post: 10-11-2009, 07:07 PM -
Database connection
By oaklander in forum New To JavaReplies: 2Last Post: 11-12-2007, 11:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks