Java and mysql together

From: Advocated (......_at_......com)
Date: 02/28/04

  • Next message: Lee Fesperman: "Re: Parse a SQL select statement"
    Date: Sat, 28 Feb 2004 01:29:11 -0000
    
    

    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


  • Next message: Lee Fesperman: "Re: Parse a SQL select statement"

    Relevant Pages

    • Re: Java and mysql together
      ... > tutorials etc of just connecting to a mysql database, ... > public sql() { ... > putting the com and org folders in Security but that had the same problem. ...
      (comp.lang.java.gui)
    • Re: OT: SQL-isti
      ... I have a quick question r.e. a SQL query. ... into my MySQL database and then move all the data into a central table. ... has a brain-dead optimiser. ... You're right to eschew scripting languages for stuff like this - ...
      (uk.rec.motorcycles)
    • SQL error
      ... I am trying to move data from a file into our mysql database. ... The format of the text file is - ipaddress ipaddress bytes packets ... The sql table is 'ipflows' ... Seems I have the sql syntax wrong but I can't seem to find the answer:( ...
      (comp.lang.python)
    • System.InvalidOperationException: Connection must be valid and open.
      ... I am using this function tu execute updates to a MySql database from a sql ... MySqlConnection conn = new MySqlConnection; ...
      (microsoft.public.dotnet.framework.adonet)