Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2013
    Posts
    64
    Rep Power
    0

    Default java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    Hello!
    I have a problem when trying to execute from the command line this row:
    java com.javasrc.webphotogallery.LoadImage myfile.jpg 1 "A picture of me in Spain"

    I set the CLASSPATH to where my jdbc .jar file resides but i'm getting this problem:

    java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
    at java.net.URLClassLoader$1.run<Unknown Source>
    at java.net.URLClassLoader$1.run<Unknown Source>
    at java.security.AccessController.doPrivileged<Native Method>
    at java.net.URLClassLoader.findClass<Unknown Source>
    at sun.misc.Louncher$AppClassLoader.loadClass<Unknown Source>
    at java.lang.ClassLoader.loadClass<Unknown Source>
    at java.lang.Class.forName0<NativeMethod>
    at com.javasrc.webphotogallery.LoadImage.main<LoadIma ge.java:23>
    The code of LoadImage.java is:
    Java Code:
    package com.javasrc.webphotogallery;
    
    import java.io.*;
    import java.sql.*;
    
    public class LoadImage
    {
      public static void main( String[] args ) 
      {
        if( args.length < 3 )
        {
          System.out.println( "Usage: LoadImage <image-filename> <album-id> <desc>" );
          System.exit( 0 );
        }
    
        String filename = args[ 0 ];
        int albumId = Integer.parseInt( args[ 1 ] );
        String desc = args[ 2 ];
        Connection conn = null;
        PreparedStatement ps = null;
        try
        {
          Class.forName( "org.gjt.mm.mysql.Driver" );
          String url = "jdbc:mysql://localhost:3306/webphotogallery";
          String username = "root";
          String password = "";
          conn = DriverManager.getConnection( url, username, password );
          ps = conn.prepareStatement( 
            "INSERT INTO Image (album_id, image_desc, image_full) VALUES( ?, ?, ? )" );
    
          ps.setInt( 1, albumId );
          ps.setString( 2, desc );
    
          // Insert the image into the second Blob
          File image = new File( filename );
          FileInputStream fis = new FileInputStream( image );
          ps.setBinaryStream( 3, fis, ( int )image.length() );
    
          // Execute the INSERT
          int count = ps.executeUpdate();
          System.out.println( "Rows inserted: " + count );
        }
        catch( Exception e )
        {
          e.printStackTrace();
        }
        finally
        {
          try 
          {
            if( ps != null ) ps.close();
            if( conn != null ) conn.close();
          }
          catch( Exception ee )
          {
            ee.printStackTrace();
          }
        }
      }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    Assuming your classpath is the same as the one on the other thread, how are you running this?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Jan 2013
    Posts
    64
    Rep Power
    0

    Default Re: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    I solved this too :) ,
    After setting the classpath i didn't resart my pc that's why i was getting this error ...
    but now i get another error :(
    java.io.FileNotFoundException myfile.jpg <The system could not find the file specified>
    at java.io.FileInputStream.open<Native Method>
    at java.io.FileInputStream.<init><Unknown Source>
    at com.javasrc.webphotogallery.LoadImage.main<LoadIma ge.java:36>
    Do you have any idea?

    Tolls, thank you very much for your disposal in responding
    Last edited by blertadhimitri; 02-01-2013 at 02:28 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    You shouldn't need to restart your pc.
    You were setting the CLASSPATH locally in the last thread.
    You haven't gone and set it in the Environment Variables have you?
    That's not the correct way of doing this.

    That new error simply means that file is not in any root of the classpath.

    Where is the file located?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Jan 2013
    Posts
    64
    Rep Power
    0

    Default Re: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    In fact i set the CLASSPATH in the environment variables ... : ^):

    myfile.jpg is located in the same directory as LoadImage...
    I copied it there...

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    Ah, then the path to it (presuming you launched your app from the directory containing 'com') is:
    com/javasrc/webphotogallery/<your file>

    Or use LoadImage.class.getResourceAsStream(<your file name>) to get an InputStream instead.
    The advantage of that is it will work should you decide to jar this code at any time.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Join Date
    Jan 2013
    Posts
    64
    Rep Power
    0

    Default Re: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

    thank you tolls,I solved the problem

Similar Threads

  1. Replies: 3
    Last Post: 12-22-2011, 09:44 AM
  2. Replies: 0
    Last Post: 11-06-2011, 12:18 AM
  3. Replies: 6
    Last Post: 02-19-2010, 01:57 PM
  4. java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    By kishan.java in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 10-19-2009, 05:34 PM
  5. Replies: 0
    Last Post: 03-21-2008, 01:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •