new programmers simpleish error help wanted

V

vivienne wykes

Hi all
I have two classes listed below .A Test class ScrubWedding class. I get the
errors listed below when I use the Test class to run the ScrubWedding class.
Could anyone with some insight pass it on . I would appreciate it greatly.

Regards
Jim Ascroft


package com.bloodoo;

import java.util.*;
import java.sql.*;

public class Test
{

public Test(){ }



public static void main (String args[])
{
String current = "";
ScrubWedding scrub = new ScrubWedding();
scrub.removeWedding(current);
}
}

public my ScrubWedding(){ }

public void removeWedding(String wedding_to_remove)
{

try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println ("after Class.forname");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:mysql://localhost/shop");
java.sql.Statement statement = connection.createStatement();
System.out.println ("afterconnection.createStatement");
statement.executeUpdate("DELETE FROM items WHERE jedi_id =
'weding_to_remove'");


if (statement != null )
statement.close();

if ( connection != null )
connection.close();


}
catch(Exception e)
{
e.printStackTrace(System.err) ;
}





}
}





java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
ÏÏ§Ï at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
ÏÏ§Ï at java.security.AccessController.doPrivileged(Native Method)
ÏÏ§Ï at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
ÏÏ§Ï at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
ÏÏ§Ï at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
ÏÏ§Ï at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
ÏÏ§Ï at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
ÏÏ§Ï at java.lang.Class.forName0(Native Method)
ÏÏ§Ï at java.lang.Class.forName(Class.java:141)
ÏÏ§Ï at com.bloodoo.ScrubWedding.removeWedding(ScrubWedding.java:20)
ÏÏ§Ï at com.bloodoo.Test.main(Test.java:17)
ÏϧÏ
ÏÏ§Ï ----jGRASP wedge2: exit code for process is 0.
ÏÏ©Ï ----jGRASP: operation complete.
¼¼ÏÏ
 
M

Murray

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

Is the MySQL driver in your classpath?
statement.executeUpdate("DELETE FROM items WHERE jedi_id =
'weding_to_remove'");

Maybe this was just for testing or something, but just in case it wasn't: I
don't think this will do what you want it to do. This will delete all ITEMS
with jedi_id = 'wedding_to_remove' <-- actual String, not the value of your
String variable.

"DELETE FROM items WHERE jedi_id = '" + wedding_to_remove + "'"
 
S

Shane Mingins

Start here ...
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

Cannot find the class org.gjt.mm.mysql.Driver. Which probably means that 1.
it is not in the classpath or 2. you haven't downloaded or 3. both :)

Could I please encourage you to do the Java tutorials, they cover lots of
the Java basics.

Oh, and if you really want to write a test for a class or method in a class
.... try www.junit.org JUnit is the standard Java unit test framework. It
would also be well worth your time to get to know it, IMO.

Shane
 
L

Liz

Shane Mingins said:
Start here ...


Cannot find the class org.gjt.mm.mysql.Driver. Which probably means that 1.
it is not in the classpath or 2. you haven't downloaded or 3. both :)

Could I please encourage you to do the Java tutorials, they cover lots of
the Java basics.

Oh, and if you really want to write a test for a class or method in a class
... try www.junit.org JUnit is the standard Java unit test framework. It
would also be well worth your time to get to know it, IMO.

Shane
I copied the mysql driver to my pc and then put in the path to the local jar
file.
 
V

vivienne wykes

Thanks Murray,

I know String wedding_to_remove is being passed in to my class and if I hard
code a weddingid value of say 5 the bean removes all wedding id 5 entries
in the database.

However I cant seem to be able to pass in wedding_to_remove into this
line ---statement.executeUpdate("DELETE FROM items WHERE weddingid = '" +
wedding_to_remove + "'");

Any insight greatfully accepted.

Regards



package com.bloodoo;

import java.util.*;
import java.sql.*;


public class ScrubWedding
{
//String weddingid ;
java.sql.PreparedStatement statement;
java.sql.Connection connection;
String wedding_to_remove;

public ScrubWedding(){ }

public void removeWedding(String wedding_to_remove)
{

try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println ("after Class.forname");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:mysql://localhost/shop");
java.sql.Statement statement = connection.createStatement();

statement.executeUpdate("DELETE FROM items WHERE weddingid = '" +
wedding_to_remove + "'");
//String output = "wedding_to_remove";
//JOptionPane.showMessageDialog(null,output,"A message to
help",JOptionPane.INFORMATION_MESSAGE);
System.out.println ("after executeUpdate");

if (statement != null )
statement.close();

if ( connection != null )
connection.close();


}
catch(Exception e)
{
e.printStackTrace(System.err) ;
}





}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top