Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013
    Posts
    69
    Rep Power
    0

    Default could not find or load main class com.javasrc.webphotogallery.LoadImage

    Hello there!
    I have a project in Enterprise Architecture called "Photo Gallery Management" .
    I decided to create a web photo gallery.As I am "new" in Java i decided to follow a step by step tutorial which is : Java Reference Guide | Project: Building a Web Photo Gallery | InformIT
    I installed Jboss,configured it on Eclipse.Then installed MySQL and MySQL Administrator becouse i have to build the database and so on.
    I created the webphotogallery-ds.xml and stored it in the deploy folder of Jboss then I had to create a java code to put an image to the database table named ' images' .The code is:
    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();
    }
    }
    }
    }

    To execute the LoadImage class, I need to include the MySQL JDBC JAR file in my CLASSPATH as follows:
    set CLASSPATH=.;<path-to-mysql-jdbc-drive>\mysql-connector-java-3.0.11-stable-bin.jar

    And then execute it as follows:

    java com.javasrc.webphotogallery.LoadImage myfile.jpg 1 "A picture of me and my friend"

    If i had been successful i would have seen sth like this: "Rows inserted: 1"
    But as i am not a successful one i get this error message from the command line:
    "could not find or load main class com.javasrc.webphotogallery.LoadImage".

    I also changed the directory to where this class resides...
    Help me please.
    I have 5 days with this problem...
    Thanks in advance

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: could not find or load main class com.javasrc.webphotogallery.LoadImage

    Locked as duplicate

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2013, 10:40 PM
  2. Replies: 1
    Last Post: 01-31-2013, 10:38 PM
  3. Replies: 1
    Last Post: 11-29-2012, 10:46 AM
  4. Could not find or load main class
    By kkid in forum New To Java
    Replies: 4
    Last Post: 10-15-2012, 05:47 AM
  5. Error: Could not find or load main class
    By Tybald in forum Eclipse
    Replies: 5
    Last Post: 05-28-2012, 12:22 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
  •