Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-14-2007, 12:33 AM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
ibanez270dx is on a distinguished road
Connecting to DB from Applet
Hi,
I'm having trouble connecting to my MySQL database from an applet. Here's the deal: I'm running on a virtual server, my page with the applet is located in such a way that it is accessible from cPanel®, JDBC is installed (and confirmed working), but I cannot connect to my database. I've tried various ways, but I keep getting the exception:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
blah blah blah
Caused by: java.io.IOException: open HTTP connection failed.
blah blah blah

I CAN connect to the DB using Java, but only through a command prompt, using the follow code I got from a tutorial:

Code:
import java.sql.*; public class JdbcExample1 { public static void main(String args[]) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql:///test", "root", "password"); if(!con.isClosed()) System.out.println("Successfully connected to MySQL server..."); } catch(Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if(con != null) con.close(); } catch(SQLException e) {} } } }
However, I just can't seem to get it right from the applet. Here is the relevent code from my applet, starting right after a button is pressed:

Code:
public void actionPerformed(ActionEvent e) { if (e.getSource() == tailnum_okButton) { String tailnumber = tailnum_TextField.getText(); if (tailnumber.equals("")) { tailnum_Label.setForeground(Color.RED); } else { search_tailnum_Label.setText(tailnumber); overallLayout.show(cardPanel, "2"); // Connect to the MySQL Database Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=password"); overallLayout.show(cardPanel, "3"); } catch (Exception c) { overallLayout.show(cardPanel, "4"); c.printStackTrace(); } finally { if (con != null) { try { con.close (); System.out.println ("Database connection terminated"); } catch (Exception c) { /* ignore close errors */ } } } } } } }
If anyone can help me, it would be greatly appreciated!!!

Thanks in advance,
- Jeff
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-14-2007, 01:51 AM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
ibanez270dx is on a distinguished road
I did some more research, and I have to pack all the drivers into a .jar file to run a DB applet from a web-browser? How do I do this?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
connecting to a database mxb7642 Database 2 08-20-2008 07:59 PM
Connecting to a Web server Java Tip java.net 0 04-07-2008 09:57 PM
Connecting to a database peiceonly New To Java 2 04-06-2008 04:28 PM
Who will know like connecting from Websphere Albert Enterprise JavaBeans 1 06-27-2007 05:41 PM
Applet, To center text and To open I engage in a dialog in an Applet Marcus Java Applets 4 06-08-2007 08:15 AM


All times are GMT +3. The time now is 10:18 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org