473,409 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Using Java to connect to local host

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.

Expand|Select|Wrap|Line Numbers
  1. private void save ()
  2. {
  3. Connection conn = null;
  4.  
  5. try
  6. {
  7. Statement stmt;
  8. String userName = "root";
  9. String password = "PASSWORD";
  10. String url = "jdbc:mysql://localhost:3306/DATABASE";
  11. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  12. conn = DriverManager.getConnection (url, userName, password);
  13. System.out.println ("Database connection established");
  14.  
  15. //Get a statement object
  16. stmt = conn.createStatement();
  17.  
  18. stmt.executeUpdate(    "INSERT INTO TABLE(Info i know to put in) VALUES('Values i know to put in')");
  19. }
  20. catch (Exception e)
  21. {
  22. System.err.println ("Cannot connect to database server");
  23.   }
  24. finally
  25.     {if (conn != null)
  26.           {try
  27.                {conn.close ();                
  28. System.out.println ("Database connection terminated");
  29.     }
  30.                 catch (Exception e) { /* ignore close errors*/  }
  31.      }
  32.    }
  33. }
  34.  
As i said above it works as a JFrame but not as a JApplet. Any help would be great.

Thanks G.
Apr 15 '08 #1
3 2369
nomad
664 Expert 512MB
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.

Expand|Select|Wrap|Line Numbers
  1. private void save ()
  2. {
  3. Connection conn = null;
  4.  
  5. try
  6. {
  7. Statement stmt;
  8. String userName = "root";
  9. String password = "PASSWORD";
  10. String url = "jdbc:mysql://localhost:3306/DATABASE";
  11. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  12. conn = DriverManager.getConnection (url, userName, password);
  13. System.out.println ("Database connection established");
  14.  
  15. //Get a statement object
  16. stmt = conn.createStatement();
  17.  
  18. stmt.executeUpdate(    "INSERT INTO TABLE(Info i know to put in) VALUES('Values i know to put in')");
  19. }
  20. catch (Exception e)
  21. {
  22. System.err.println ("Cannot connect to database server");
  23.   }
  24. finally
  25.     {if (conn != null)
  26.           {try
  27.                {conn.close ();                
  28. System.out.println ("Database connection terminated");
  29.     }
  30.                 catch (Exception e) { /* ignore close errors*/  }
  31.      }
  32.    }
  33. }
  34.  
As i said above it works as a JFrame but not as a JApplet. Any help would be great.

Thanks G.
do a google search on this one JApplet and Database. You will find a couple solutions that will help you. One is called Signed

nomad
Apr 16 '08 #2
Hi Nomad,

I know about signing applets. I've done this ok and i get no error messages returned.

Could it be, because i'm connecting directly to the local host or should i use the ip address?

G
Apr 16 '08 #3
ajos
283 100+
Hi Nomad,

I know about signing applets. I've done this ok and i get no error messages returned.

Could it be, because i'm connecting directly to the local host or should i use the ip address?

G
How about printing the stacktrace instead of leaving it empty.ip is not required here. check the mysql docs to connect to a java application/applet.
Apr 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lorenzo | last post by:
hi you all, first of all apologies for having cross-posted this message but really i did not know where to post it. please let me know what ng you consider the most suitable for the described...
6
by: Jeff Sandler | last post by:
I have a database I created in mySQL. I've been entering data every day into the database using a Java application that I wrote. The database and the Java program are on the same Win 98 SE...
3
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
by: anaik100 | last post by:
am trying to run a java db2 program. my db2 is in os/390. below is the code public class T4DB2Connect { public static void main(String args) { try { // load the DB2 Driver...
1
rsrinivasan
by: rsrinivasan | last post by:
Hi, I am Sending mail from java. When I run the program I hava Following error.. DEBUG: setDebug: JavaMail version 1.4ea DEBUG: getProvider() returning javax.mail.Provider DEBUG SMTP:...
0
by: IvanJ2EE | last post by:
Hello partners. I have some troubles trying to connect to a remote database from a Java Class. I`m using the following code: String DRIVER = "COM.ibm.db2.jdbc.app.DB2Driver"; String URL =...
1
by: creative1 | last post by:
When I test the application I get follwowing error: could not connect to smtp host: connection timeout error can someone please check if I have rigth settings? Where I am wrong here Is IP and...
3
by: TsanChung | last post by:
I want to make a java TCP socket client to communicate with a TCP server socket on linux. Are there some sample C unix server and java client socket programs available? The Richard Stevens'...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.