Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2004

Tip: Looking for answers? Try searching our database.

Java and mysql together

Thread view: 
Advocated - 28 Feb 2004 01:29 GMT
Hi there, this is my last hope of using sql, ive collected loads of
tutorials etc of just connecting to a mysql database, but so far all have
been the same, therefore none have worked.

This is my code so far:
############################################################################
package Security;
import java.sql.*;

public class sql extends javax.swing.JFrame {

   public sql() {
       initComponents();
       String url = "jdbc:mysql://localhost:3306/javalogin";

       try{
           Class.forName("com.mysql.jdbc.Driver").newInstance();
           Connection con=DriverManager.getConnection(url,"myusername",
"mypass");
           Statement stmt = con.createStatement();
           stmt.executeUpdate("INSERT INTO users " +  "VALUES ('180',
270)");
       }
       catch(Exception e){
           System.out.println(e);
       }
   }

   private void initComponents() {

       addWindowListener(new java.awt.event.WindowAdapter() {
           public void windowClosing(java.awt.event.WindowEvent evt) {
               exitForm(evt);
           }
       });
       pack();
   }
   private void exitForm(java.awt.event.WindowEvent evt) {
       System.exit(0);
   }
   public static void main(String args[]) {
       new sql().show();
   }
}
##############################################################

the idea is i connect to the javalogin database, and then try and add some
values into a table called users.
My mysql tables/databases have already been created and are fine.

Problem comes when i run it, it compiles ok, but on run i get this error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Im not sure what im doing wrong, but the way my program is with its folders
etc is:

C:\Security\ then all my files are in here:
This includes:
sql.java, sql.class, mysql.jar - i also tried unpacking this and just
putting the com and org folders in Security but that had the same problem.

I just cant work this out, Any ideas please
Lloyd - 28 Feb 2004 04:25 GMT
> Hi there, this is my last hope of using sql, ive collected loads of
> tutorials etc of just connecting to a mysql database, but so far all have
> been the same, therefore none have worked.
>
> This is my code so far:

############################################################################
> package Security;
> import java.sql.*;
[quoted text clipped - 50 lines]
> sql.java, sql.class, mysql.jar - i also tried unpacking this and just
> putting the com and org folders in Security but that had the same problem.

What is the command line you are using to run this app? I suspect it's a
classpath problem.
Advocated - 28 Feb 2004 08:07 GMT
<Snip<

> What is the command line you are using to run this app? I suspect it's a
> classpath problem.

Well, ive been running it via JCreator, not directly thorough the CLI
Advocated - 29 Feb 2004 16:19 GMT
I still have'nt been able to fix this, any ideas how to do it via JCreator?

Cheers


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.