Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 11
There are 1 users currently browsing forums.
Java Programming Created by Sun Microsystems, Java remains to be one of the most powerful, cross-platform languages of choice by professionals everywhere. Capable of creating advanced desktop applications and web services, Java is tough to master, so ask your questions here.

Reply
  #1  
Old 06-13-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Linking jar files into java applets

Hi Guys,

I have a question about how to link a jar file (the mysql connection one) in with a java applet. I have been playing around with it for about an hour now and I still keep getting the "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" exception.

I have run the applet through Eclipse and it works perfectly but when I tried to link it through a web page I get that error message. Can someone please point me in the right direction?

Code:
import java.applet.Applet;

import javax.swing.JLabel;
import javax.swing.JPanel;


public class
Code:
Hangman extends Applet
{
    Connect conn;
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    public void init ()
    {
        int userId = 1;//Integer.parseInt ( this.getParameter ( "uid" ) );
        String pwd = "test";//this.getParameter( "pass" );
        
        this.conn = new Connect();
        if ( this.conn.checkCreds( userId, pwd ) )
        {
            this.add(new game());
        }
        /*else
        {
            System.out.println ( "ERROR - Invalid User Id/Password Combination" );
        }*/
    }
    
    private class game extends JPanel
    {
        public game()
        {
            JLabel tmp = new JLabel ( "YAY" );
            this.add( tmp );
        }
    }

}


Code:
import java.lang.*;
import java.sql.*;
import java.util.*;

import javax.swing.JOptionPane;

public class Connect
{
    Connection myConn = null;        

    Statement stmt = null;
    ResultSet rs = null;
    
    public Connect()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");

            myConn = DriverManager.getConnection("jdbc:mysql://databaselink:3306/tablename", "username", "password");

            stmt = myConn.createStatement();
            if ( stmt == null )
            {
                System.out.println ( "ERROR" );
                return;
            }
        }
        catch(Exception e)
        {
            System.err.println(e);
        }

    }
    
    public boolean checkCreds ( int userId, String pwd )
    {
        try
        {
            if ( stmt == null )
        {
            System.out.println ( "ERROR" );
            return false;
        }
            rs = stmt.executeQuery( "SELECT `id` FROM `users` WHERE `id` = " + userId + " AND password = '" + pwd + "'" );
            rs = stmt.getResultSet();
            rs.next();
            if ( rs.getInt("id") == userId )
            {
                return ( true );
            }
            else
            {
                return ( false );
            }
        }
        catch ( SQLException s )
        {
            return ( false );
        }
    }
}
Code:
<applet code="Hangman.class" width=200 height=200 CODEBASE="./">
<param name=pass value="test">
<param name=uid value="1">
<param name=archive value="Hangman.jar, mysql-connector.jar" />
</applet>

<APPLET CODE="Hangman.class" ARCHIVE="Hangman.jar, mysql-connector.jar" 
HEIGHT="500" WIDTH="400" ALIGN="bottom" CODEBASE="./">
<param name=pass value="test">
<param name=uid value="1">
<param name=archive value="Hangman.jar, mysql-connector.jar">
</APPLET>

<object classid="java:Hangman.class"
              type="application/x-java-applet"
              archive="Hangman.jar, mysql-connector.jar"
              height="40" width="200" >
              
<applet code=Hangman.class name=Hangman archive="Hangman.jar, mysql-connector.jar"
    width=300 height=300>
    <param name="bgcolor" value="ffffff">
    <param name="fontcolor" value="000000">
    Your browser is not Java enabled.
</applet>

<applet code=Hangman.class width="200" height="200" >
I have made both a jar file for the
Hangman.class (Hangman.jar which contains the mysql-connector.jar).

Any help would be greatly appreciated.

Thanks,
~juddster
Reply With Quote
  #2  
Old 06-13-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

I just tried it again at home and got the following errors on my java console with all of those 4 java calls.

http://pastebin.com/f2770d5d3
Thank you very much,
~juddster
Reply With Quote
  #3  
Old 06-13-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

PS - I just noticed a little error in my first post but I don't want to touch it because apparently YC doesn't like me very much right now...so please just ignore the top code box ~juddster
Reply With Quote
  #4  
Old 06-14-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

I thought I hit Edit. This post can be deleted..
Reply With Quote
  #5  
Old 06-14-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

Okay...so I have it giving an "AccessControlException" when I try to connect to the database through the JDBC driver. Any suggestions on how to fix this?

http://pastebin.com/faef9c54

That is the output from Java Console.

Code:
<applet code="wrap.class" width=200 height=200>
<param name=pass value="test">
<param name=uid value="1">
<param name=archive value="mysql-connector.jar" />
</applet>
That is the code I use to display the applet. wrap is just a class I made that would try to connect to the database.

Any help would be greatly appreciated.

Thank you,
~juddster
Reply With Quote
  #6  
Old 06-26-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

No suggestions for me?

~juddster
Reply With Quote
  #7  
Old 06-26-2008
Jhi Jhi is offline
Child
 
Join Date: Jan 2008
Location: Oswego, New York
Age: 23
Posts: 93
Rep Power: 3
Jhi is on a distinguished road
Re: Linking jar files into java applets

Code:
java.io.IOException: Server returned HTTP response code: 403 for URL: http://www.dev.cyopets.com/javaApplets/mysql-connector.jar
I'd look into that first.
Reply With Quote
  #8  
Old 06-28-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

I have that already dealt with. My post further down has a link to the new errors that I'm having.

~juddster
Reply With Quote
  #9  
Old 07-02-2008
Jhi Jhi is offline
Child
 
Join Date: Jan 2008
Location: Oswego, New York
Age: 23
Posts: 93
Rep Power: 3
Jhi is on a distinguished road
Re: Linking jar files into java applets

Why do you think you're being denied access?
Reply With Quote
  #10  
Old 07-03-2008
Toddler
 
Join Date: Nov 2007
Posts: 29
Rep Power: 0
juddster is on a distinguished road
Re: Linking jar files into java applets

I have no idea why I'm getting the Access Denied...the server says that we are allowed to have java applets connecting. I made my database user info available through any IP Address so I don't think that is the problem...

Any ideas?

~juddster
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

BB 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
How to copy *.vob files on DVD to the hard disk and merge them together zengpeiwen1719 Video Shack 0 05-26-2008 11:21 PM
C/C++ faster than Java? shai General Programming 22 07-01-2006 01:23 PM
JAVA tutorial CHAPTER #1 omanofmysteryp Articles, Tutorials, and Guides 6 05-01-2005 07:43 AM