Results 1 to 2 of 2
Thread: Connecting to DB from Applet
- 11-13-2007, 10:33 PM #1
Member
- Join Date
- Nov 2007
- Location
- Bay Area, CA
- Posts
- 13
- Rep Power
- 0
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:
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:Java 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) {} } } }
If anyone can help me, it would be greatly appreciated!!!Java 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 */ } } } } } } }
Thanks in advance,
- Jeff
- 11-13-2007, 11:51 PM #2
Member
- Join Date
- Nov 2007
- Location
- Bay Area, CA
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
connecting to a database
By mxb7642 in forum JDBCReplies: 5Last Post: 09-08-2009, 08:39 AM -
Connecting to a Web server
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 07:57 PM -
Connecting to a database
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2008, 02:28 PM -
Who will know like connecting from Websphere
By Albert in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 06-27-2007, 03:41 PM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks