HELP with mySQL!!

Im trying to connect to Mysql using MySQL Connector/J , but always found this error message when executing it
"java.lang.ClassNotFoundException: com.mysql.jdbc.Driver".
i have the JAR file in C:\JDBC and C:\jdk1.5.0\jre\lib\!
i set my CLASSPATH like below
C:\jdk1.5.0\jre\lib\mysql-connector-java-bin.jar;c:\jdk1.5.0\lib\tools.jar;c:\jdk1.5.0\lib\dt.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\classes;C:\Program Files\Apache Software Foundation\Tomcat 5.5\lib;C:\JDBC;
codes are below
import java.sql.*;
public class main {
/** Creates a new instance of main */
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
public static void main(String[] args) {
try {
Class.forName(JDBC_DRIVER).newInstance();
System.out.println("Driver loaded");
} catch (Exception ex) {
System.out.println(ex.toString());
HELP PLEASE!!!!!!!

Look at some of these I got from the search - I am sure you will determine the problem.
http://search.sun.com/search/developers/index.jsp?and=%22java.lang.ClassNotFoundException%3A+com.mysql.jdbc.Driver&nh=10&phr=&qt=&not=&field=&since=&col=devforums&rf=0&Search.x=15&Search.y=8
It looks like a classpath problem.

Similar Messages

  • Help with mySQL Connection string

    Here is hoping someone can help & once I get it down I promise I'll post all my work on this list so some other newbie can benefit.
    I'm simply trying to run a very very straightforward JDBC test with mySQL & I keep getting the "Server configuration denies access to data source" error. But before you tell me that I must simply look at what my mysql.db & mysql.user table allows - I'VE TRIED THAT. I realize that the error is probably there somewhere - but I can't see it.
    I've tried connecting with 2 different accounts - the provided "root" & a user I created "deep" to 2 different databases the provided "test" & "testdb" which I created) . Here is what mysql says about the two different databases
    mysql> select * from db;
    Host  | Db         | User |.......
    -----+------------+-------
    | %         | test    |       | ......
    | %         | test\_% |     | ........
    | localhost | testdb  | deep |........Note that "root" should have access to "test" & deep@localhost should have access to "testdb" right?
    So here are all the connection strings I have tried - all return the same error below
            Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test", "root", "mypass"
    //            "jdbc:mysql://localhost:3306/testdb", "deep", "mypass"
    //            "jdbc:mysql://localhost/testdb?user=deep&password=mypass"
    //            "jdbc:mysql://localhost/testdb", "deep", "mypass"
    //            "jdbc:mysql://localhost:3306/testdb?user=deep@localhost&password=mypass"
    //            "jdbc:mysql://localhost:3306/testdb?user=deep&password=mypass"
    //            "jdbc:mysql://localhost/testdb", "deep@localhost", "mypass"
    //            "jdbc:mysql:///test", "root", "mypass"
    //            "jdbc:mysql://localhost/test", "root@localhost", "mypass"
    );My Error:
    Exception in thread "main" java.sql.SQLException: Server configuration denies access to data source
            at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:193)
            at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
            at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
            at org.gjt.mm.mysql.Driver.connect(Driver.java:167)
            at java.sql.DriverManager.getConnection(DriverManager.java:517)
            at java.sql.DriverManager.getConnection(DriverManager.java:199)
            at TestMySQL4.main(TestMySQL4.java:76)BTW:
    I am using MacOSX 10.1
    MySQL 3.23.42
    The driver is: mm.mysql-2.0.6.jar
    Please help!
    'deep

    hi amandeep
    well i m getting the same error message when trying to connect MYSQL using mm.jdbc driver.
    java.sql.SQLException : Server configuration denies access to data base source.
    query.jdbcDriver org.gjt.mm.mysql.Driver
    query.databaseURL jdbc:mysql://aaa.bbb.com/pluto
    query.databaseUserName samin
    query.databasePwd samin
    query.summaries true
    i hve installed mysql on server aaa.bbb.com network 1
    and trying to run application on network 2
    Thanks
    samir

  • Need help with MySQL connection error _mmServerScripts

    Trying to create insert a recordset I got the message:
    "The files from the _mmServerScripts folder are for the server model PHP-MySQL. You try to connect to a database using a different server model .Please remove this folder outside the Dreamweaver environment on both local and testing machines and try again."
    I've searched the net and have seen this message hunting people since dw8...
    I could not find a "cure".
    Things to notice:
    0 - Yes the whole thing is apache/php/mysql... just DW thinks it's not.
    1 - Both the connection and the Recordset actualy works. I have a whole site based on this connection and the recorsets I've created manualy based on it.
    2 - It does not matter if we erase or not the _mmServerScripts folder the message stands still allover.
    3 - The problem seems to show up when you split servers...
    3.1 - If I test in a WAMP environment where apache and mysql are in the same machine I can use DW to create data objects for me.
    3.2 - If I test in my real test environment which have web server and db server separated from each other then I can't use DW to create data objects, see bindings, behaviours etc... all I get is this message.... while the code itself runs fine anyway.
    Does any one already knows how to work around or fix this?
    Thanks,
    Julio

    Thanks PZ,
    Yes everything is fine with the site definition.
    everything works. I can upload, run, test all ok.
    The only thing that does not work is to insert any sort of data object through DW interface. If I declare my reordsets by hands or even If I use the ones DW created in my local test server all works fine.
    Then if I use the site definition and try to see any bindings or create a recordset or create a new connection using dw... then the messages come up and dw can't go any further in that task.
    By spli servers I mean one phisical linux server with apache/php but without mySQL + one physical Linux server with mySQL but without apache/php.
    So when I use a site definition that points either to a WAMP or LAMP i.e. when everything is in the same machine DW goes happy and does whatever it's asked to do.
    When I try that on the real mccoy environment (with the two separated servers)... It looks like DW gets confused...

  • Need Help with mysql admin for Mac

    Hello all.
    I am new to cold fusion and databases all together. Infact I
    am doing an online tutorial to get me started, my problem is the
    tutorial really just scratches the surface for the mac side and in
    some cases sorta explains how to do but no visual help and I am
    very visual.
    I am searching for software that is really idiot proof to
    start my knowledge with then make the transition when I learn more
    and more to hard coding. The tutorial suggests Navicat for Mysql
    admin and it is nice but he is setting up basic databases in Access
    which looks really easy and I am trying to follow along with
    navicat but I am just not getting it specifically when it comes to
    setting up relationships between tables. Can I use a software like
    FileMaker Pro and just convert to mysql or is their other software
    that makes it a little more easy to understand how to set up
    relationships like access does.
    I am totally new to this stuff and I am looking for the
    easiest product to use. Thanks again for your help and time.
    Chris

    As for the database part, before you write your first query,
    you should become grounded in the concepts of data modeling. Then
    find a good source (book, books-on-line, etc. ) for the particular
    "flavor" of SQL used by your database of choice, then start writing
    your queries. Data model first (entities, relationships,
    attributes), then SQL.
    Couple of fairly good online tutorials for data modeling.
    Introduction
    to Data Modeling and
    Data Model
    Reference
    Master this and you will save yourself many hours of grief,
    trust me.
    Phil

  • Help with MySQL/PHP Connection

    Hi,
    I'm making a site that requires the storage of information via MySQL.  I've set up my testing server, and it connects fine.  When I try to add a MySQL connection, however, I keep getting the "HTTP Error Code 404: File Not Found" error.  I've tried using both the MySQL server provided by my web host and one hosted on my own computer (using "localhost" as the server), but both give me the same error.  The error box says that perhaps:
    1) There is no testing server running on the server machine.
    2) The testing server specified for this site does not map to the http://**mywebsite**.com/_mmServerScripts/MMHTTPDB.php URL.  Verify that the URL Prefix maps to the root of the site.
    I'm certain it's not #1, because both of my MySQL servers work fine outside of Dreamweaver.  But I'm not quite sure what #2 is saying.  Any help?
    Thanks in advance.

    nickf77 wrote:
    I have my testing server set up at my FTP account that came with my hosting package.  Should it not be?
    It's not ideal, but you can do it that way. The principle is still the same.
    When using a remote connection, the value of Host directory is the same as you use for FTP connections to your remote site. In many cases, this is left blank, is simply a forward slash, or is something like public_html. In any event, it's the root level of your website.
    URL prefix is also the root level of your site, but expressed as a URL: http://www.example.com/.
    Host directory and URL prefix must both point to the same place. The first is a path, the second is a web address.

  • New Bie help with MySQL & servlet

    Hi,
    I am trying to execute a small action... some how my code does not work. All it shows is a blank page with no error....
    Can any one help me to optimize this code so that it works?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package oneword;
    import com.mysql.jdbc.Connection;
    import com.mysql.jdbc.Statement;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Random;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class Register extends HttpServlet {
        private String name = null;
        private String emailID = null;
        private String nameDB = "jdbc:mysql://localhost:3306/register";
        private String mysqlUser = "root";
        private String mysqlPassword = "abc";
        private String mySqlJdbcDriver = "com.mysql.jdbc.Driver";
        private Connection conn = null;
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException, SQLException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            name = request.getParameter("_name");
            emailID = request.getParameter("_email");
            try {
                Random generator = new Random();
                int activationPassword = generator.nextInt(100000);
                Class.forName(mySqlJdbcDriver);
                conn = (Connection) DriverManager.getConnection(nameDB,mysqlUser,mysqlPassword);
                Statement statement = (Statement) conn.createStatement();
                String sqlCommand = "INSERT INTO userdata(name, email, validation, " +
                        "banned, activatepassword, password)values("+name+", "+emailID+", 0, 0,"+activationPassword+", 'ddd')";
                statement.executeQuery(sqlCommand);
                out.println(name);
                out.println("<br>"+emailID);
                out.println("rows affected:");
                conn.close();
            } catch (SQLException ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
            } finally {
                out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
         * Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try {
                processRequest(request, response);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
         * Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try {
                processRequest(request, response);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
    }Thank you

    A blank page usually indicate that an exception is been thrown but cannot be displayed because the response is already started/committed/processed. Just read the appserver's logs as usual for the details.
    Your servlet class does way too much. You're mingling all the processing steps together in one class. This is simply asking for trouble. Use a DAO class for accessing the DB. Use a JSP file for presentation. Use a business object to process the input/output data. Use a servlet for controlling the request. To start off, you may get some ideas out of this article and the JSP/Servlet follow-up: [http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html].
    Oh, your JDBC code is not safe against SQL injection attacks either.

  • Help with mysql query plz anyone i am begging!!!

    Hi everyone pls forgive me i am new to java. can someone pls tel me where i am going wrong wit this mysql query?
    <sql:query var="parish" maxRows="1" dataSource="jdbc/gav">
    SELECT ParishName, OwnerOccupierHousehold, OwnerOccupierPercOfOverall, OwnerOccupierCo2Emissions,
    SocialRentedHousehold, SocialRentedPercOfOverall, SocialRentedCo2Emissions, PrivateRentedHousehold,
    PrivateRentedPercOfOverall, PrivateRentedCo2Emission, TotalHouseholds, TotalPerc, Average,
    Total2001, TotalEstimatedTotal2006, EmissionsPerPerson, EmissionPerHousehold, EmissionsPerParish,
    EnergyChampionsNeeded, NumberOfPeopleAtWork, NumberOfSchoolAgeChildren
    FROM base_data as b
    WHERE b.id = ? <sql:param value="${param.id}"/>
    <sql:param value="${param.id}"/>
    </sql:query>
    <c:set var="parish" scope="request" value="${parish.rows[0]}"/>
    here is the error i get:
    java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
    please any help would be appreciated!!! Thanks in advance guys .

    here is my code for the form on the index page:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <sql:query var="parish" dataSource="jdbc/gav">
    SELECT id, ParishName FROM base_data
    </sql:query>
    <form action="response.jsp">
    Select a Parish: <select name="id">
    <c:forEach var="parish" items="${parish.rows}">
    <option value="${parish.id}">${parish.ParishName}</option>
    </c:forEach>
    </select><br><input type="submit" value="submit" name="submit" /></form>
    here is the code for the response page:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <sql:query var="parish" maxRows="1" dataSource="jdbc/gav">
    SELECT b.id, b.ParishName, b.OwnerOccupierHousehold, b.OwnerOccupierPercOfOverall, b.OwnerOccupierCo2Emissions,
    b.SocialRentedHousehold, b.SocialRentedPercOfOverall, b.SocialRentedCo2Emissions, b.PrivateRentedHousehold,
    b.PrivateRentedPercOfOverall, b.PrivateRentedCo2Emission, b.TotalHouseholds, b.TotalPerc, b.Average,
    b.Total2001, b.TotalEstimatedTotal2006, b.EmissionsPerPerson, b.EmissionPerHousehold, b.EmissionsPerParish,
    b.EnergyChampionsNeeded, b.NumberOfPeopleAtWork, b.NumberOfSchoolAgeChildren
    FROM base_data as b
    WHERE b.id = ? <sql:param value="${param.id}"/>
    </sql:query>
    <c:set var="parish" scope="request" value="${parish.rows[0]}"/>
    i display the results like this : ${parish.EmissionsPerParish}
    the user should be able to select a parish from a form and then sql query created and then i want to show the row results on the response page.
    could you tell me where so should be a simple process although not simple enough as it may seem.
    thanks for the advice keith

  • Help with mysql class (Japplet)

    Hi,I have found program that exactly what i want in Japplet ,but its not clean i wana use it on my other classes . Here is what i tired from changing .After all,i am not professionnel in java.
    The ORGINAL HERE :
      http://forum.java.sun.com/thread.jsp?forum=4&thread=197844
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.net.URL;
    import java.sql.*;
    import java.util.*;
    import java.util.Properties;
    import java.net.URL;
    import java.sql.*;
    public class Sql extends JApplet
        public String  tfDrv = null, tfSQL = null;
        //public String dbUser,dbPass;
        Connection conn = null;
        private Statement stmt =null;
        /*public Sql() {
        public void init() {
        private void initialize( String dbUser,String dbPass,String tfDrv ) {
                initDB("jdbc:mysql://localhost/mysql",dbUser,dbPass,tfDrv);
        private void initDB(String connect,String user,String pass,String tfDrv) {
        try {
            String url = connect;
            this.tfDrv=tfDrv;
            Class.forName("org.gjt.mm.mysql.Driver");
            conn = DriverManager.getConnection( url, user, pass );//should get name, pwd
        } catch( Exception e ) {
            e.printStackTrace();
        public ResultSet executeSQL( String sql )  throws Exception {
        System.out.println( "DS exSQL " + sql );
        int irs = 0;
        ResultSet rs = null;
        try {
            stmt = conn.createStatement();
            boolean bo = stmt.execute("use "+ this.tfDrv);
            if( sql.startsWith( "select" ) ) {
            rs = stmt.executeQuery( sql );
            System.out.println( "xq rs: " + rs );
            else if( sql.startsWith( "delete" ) ||
                 sql.startsWith( "insert" ) ) {
            irs = stmt.executeUpdate( sql );
            else if( sql.startsWith( "update" ) ) {
            irs = stmt.executeUpdate( sql );
        catch( Exception e ) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            throw e;
        return rs;
        private DefaultTableModel doSQL( String sql ) {
        DefaultTableModel m = new DefaultTableModel();
        java.util.Vector data = new java.util.Vector();
        java.util.Vector headers = new java.util.Vector();
        try {
            String s = "";
            ResultSet rs = executeSQL( sql );
            System.out.println( "rs " + rs );
            ResultSetMetaData rsmd = rs.getMetaData();
            ////List datas  = new LinkedList();   
            ////datas = new ArrayList();
            for( int c = 1, cc = rsmd.getColumnCount(); c <= cc; c++ ) {
            headers.addElement( rsmd.getColumnName( c ) );
            java.util.Vector datum = null;
            while( rs.next() )
                datum = new java.util.Vector();
                for( int c = 1, cc = rsmd.getColumnCount(); c <= cc; c++ ) {
                s = rs.getString( c );
                datum.addElement( s );
                data.addElement( datum );
        } catch( Exception e ) {
            e.printStackTrace();
        m.setDataVector( data, headers );
        System.out.println( "d: " + data );
        return m;
        public static void main( String[] args )   throws Exception{
        Sql rb = new Sql();
        ResultSet rs;
        rb.initialize( "root","root","test" );
         //rb.doSQL("DELETE FROM `oop` WHERE `oop`.`java` = 2");
        rs = rb.executeSQL("DELETE FROM `oop` WHERE `oop`.`java` = 2");
        System.out.println(rs.getString("1"));
    }

    Ok Sorry
    This the same program after edditing and its works great
    but the problem i don't want GUI I want to use it in other classes to connect to mysql database .So please Help.
      http://forum.java.sun.com/thread.jsp?forum=4&thread=197844
            permission java.lang.RuntimePermission "accessClassInPackage.sun.jdbc.odbc";
         permission java.util.PropertyPermission "file.encoding", "read";
            permission java.net.SocketPermission "*:*", "connect,listen,resolve,accept";
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.net.URL;
    import java.sql.*;
    import java.util.*;
    import java.util.Properties;
    import java.net.URL;
    import java.sql.*;
    public class yesSql extends JApplet
        private JTextField tfDrv = null, tfSQL = null;
        Connection conn = null;
        private Statement stmt =null;
        public yesSql() {
        public void init() {
         initialize( (JPanel) getContentPane() );
        private void initialize( JPanel p ) {
         p.setLayout( new BorderLayout() );
         JLabel lDrv = new JLabel( "DB Name: " );
         tfDrv = new JTextField( 25 );
         tfDrv.setText( "mysql" );
         JPanel pp = new JPanel();
         pp.setLayout( new GridLayout( 6, 2 ) );
         pp.add( lDrv );
         pp.add( tfDrv );
         JLabel lSQL = new JLabel( "SQL" );
         tfSQL = new JTextField( 25 );
         tfSQL.setText( "select * from " );
         pp.add( lSQL );
         pp.add( tfSQL );
         JButton b = new JButton( "Submit" );
         b.addActionListener( new ActionListener() {
              public void actionPerformed( ActionEvent ev ) {
                 initDB("jdbc:mysql://localhost/mysql","root","root");
                  initTable( (JPanel) getContentPane() );
         pp.add( b );
         p.add( "North", pp );
        private void initDB(String connect,String user,String pass) {
         try {
             String url = connect;
             String drv = tfDrv.getText();
    //         DriverManager.registerDriver( new sun.jdbc.odbc.JdbcOdbcDriver() );
            Class.forName("org.gjt.mm.mysql.Driver");
             conn = DriverManager.getConnection( url, user, pass );//should get name, pwd
             System.out.println( "d: " + drv + ", u: " + url );
         } catch( Exception e ) {
             e.printStackTrace();
        public ResultSet executeSQL( String sql ) throws Exception {
         System.out.println( "DS exSQL " + sql );
         int irs = 0;
         ResultSet rs = null;
         try {
             stmt = conn.createStatement();
             boolean bo = stmt.execute("use "+ tfDrv.getText());
             if( sql.startsWith( "select" ) ) {
              rs = stmt.executeQuery( sql );
              System.out.println( "xq rs: " + rs );
             else if( sql.startsWith( "delete" ) ||
                   sql.startsWith( "insert" ) ) {
              irs = stmt.executeUpdate( sql );
             else if( sql.startsWith( "update" ) ) {
              irs = stmt.executeUpdate( sql );
         catch( Exception e ) {
             System.out.println(e.getMessage());
             e.printStackTrace();
             throw e;
         return rs;
        private DefaultTableModel doSQL( String sql ) {
         DefaultTableModel m = new DefaultTableModel();
         java.util.Vector data = new java.util.Vector();
         java.util.Vector headers = new java.util.Vector();
         try {
             String s = "";
             ResultSet rs = executeSQL( sql );
             System.out.println( "rs " + rs );
             ResultSetMetaData rsmd = rs.getMetaData();
             for( int c = 1, cc = rsmd.getColumnCount(); c <= cc; c++ ) {
              headers.addElement( rsmd.getColumnName( c ) );
             java.util.Vector datum = null;
             while( rs.next() )
                  datum = new java.util.Vector();
                  for( int c = 1, cc = rsmd.getColumnCount(); c <= cc; c++ ) {
                   s = rs.getString( c );
                   datum.addElement( s );
                  data.addElement( datum );
         } catch( Exception e ) {
             e.printStackTrace();
         m.setDataVector( data, headers );
         System.out.println( "d: " + data );
         return m;
        private void initTable( JPanel p ) {
         DefaultTableModel dtm = doSQL( tfSQL.getText() );
         JTable tb = new JTable( dtm );
         JScrollPane sp = new JScrollPane( tb );
         JFrame fr = new JFrame();
         fr.getContentPane().add( sp );
         fr.pack();
         fr.show();
        public static void main( String[] args ) {
         JFrame f = new JFrame();
         yesSql rb = new yesSql();
         JPanel p = (JPanel) f.getContentPane();
         rb.initialize( p );
         f.pack();
         f.show();
    }

  • Help with mysql URGENT!!

    i get the error....
    warning: supplied argument is not a valid MySQL result resource in /var/www/html/php/db1.php on line 18
    line 18 being....
    while ($row = mysql_fetch_row($resultID)
    code for printing data is here
    none of my data prints
    PLEASE HELP ME, THANKS IN ADVANCE FOR YOUR HELP.
    htnaks,
    ELVIS

    are you sure this is your code?
    while ($row = mysql_fetch_row($resultID)
    code for printing data is here
    It misses a right ) at the first line.
    PC

  • Need help with mysql-connector-j setup!

    I have downloaded and installed Tomcat 5.5 and MySQL Server 5.0 and have both up and running. I then downloaded the MySQL-Connector-J and the folder is located at:
    C:\Program Files\Java\jre1.5.0_06\lib\ext\mysql-connector-java-3.1.12
    My JSP code looks like this:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <%@ page import="java.net.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="java.sql.*" %>
    <%
         try{
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         catch (Exception E) {
         out.println("Unable to load driver. " + E);
    %>And I am getting the folowing error:
    java.lang.ClassNotFoundException: com.mysql.jdbc.DriverNow, before anyone tells me to go read other posts, I have already done this and I have tried changing my classpath with no luck. I have tried these locations as my classpath:
    C:\Program Files\Java\jre1.5.0_06\lib\ext\mysql-connector-java-3.1.12
    C:\Program Files\Java\jre1.5.0_06\lib\ext\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar
    Neither of which seem to work. Can anyone figure out what's happening here?

    Ok, I copied it to the <tomcat dir>/common/lib, but I copied the entire folder (which I'm assuming is necessary), with no luck. So, now the location is:
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar
    Any other suggestions?
    Thanks.
    null

  • Need help with MySQL Query...Again

    Ok so I get this error when I enter "springfield" and "MA" for the city and state.
    This server program accepts either a 'zipcode' or 'city, state' depending on the choice # passed to it.
    I just need to be able to perform the query.
    Thanks!!
    java.sql.SQLException: Unknown column 'springfield' in 'where clause'
    Error4
         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
         at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
         at com.mysql.jdbc.Connection.execSQL(Connection.java:2949)
         at com.mysql.jdbc.Statement.executeQuery(Statement.java:959)
         at ThreadConnect.run(ZipcodeServer.java:84)Here is my code:
    import java.sql.*;
    import java.io.*;
    import java.net.*;
    public class ZipcodeServer {
         static void runServer() {
              ServerSocket server;
              Socket connection;
              try {
                   System.out.println("Creating Server Socket " + 5000 + " . . . ");
                   server = new ServerSocket(5000);
                   System.out.println("SUCCESS!!!");
                   while (true) {
                        System.out.println("Waiting for connection.");
                        connection = server.accept();
                        System.out.println("Done");
                        ThreadConnect t = new ThreadConnect(connection);
                        t.start();
              } catch (IOException e) {
                   System.out.println("Error5");
                   e.printStackTrace();
         public static void main(String args[]) {
              ZipcodeServer.runServer();
    class ThreadConnect extends Thread {
         Socket connection;
         DataOutputStream output;
         DataInputStream input;
         ThreadConnect(Socket x) {
              connection = x;
         public void run() {
              try {
                   input = new DataInputStream(connection.getInputStream());
                   output = new DataOutputStream(connection.getOutputStream());
                   try {
                        int choice = input.readInt();
                        String city, state;
                        int zipcode;
                        if (choice == 1) {
                             int zc = input.readInt();
                             DatabaseConnection.connect();
                             DatabaseConnection.rs = DatabaseConnection.s
                                       .executeQuery("SELECT City,State FROM Zipcodes "
                                                 + "WHERE ZipCode = " + zc);
                             while (DatabaseConnection.rs.next()) {
                                  state = DatabaseConnection.rs.getString("State");
                                  output.writeUTF(state);
                                  output.flush();
                                  city = DatabaseConnection.rs.getString("City");
                                  output.writeUTF(city);
                                  output.flush();
                        } else if (choice == 2) {
                             city = input.readUTF();
                             state = input.readUTF();
                             DatabaseConnection.connect();
                             DatabaseConnection.rs = DatabaseConnection.s
                                       .executeQuery("SELECT ZipCode FROM Zipcodes "
                                                 + "WHERE City = " + city + " AND State = "
                                                 + state);
                             while (DatabaseConnection.rs.next()) {
                                  zipcode = DatabaseConnection.rs.getInt("ZipCode");
                                  output.writeInt(zipcode);
                                  output.flush();
                   } catch (Exception e) {
                        System.out.println("Error4");
                        e.printStackTrace();
                   } finally {
                        DatabaseConnection.close();
              } catch (IOException e) {
                   System.out.println("Error3");
                   e.printStackTrace();
    class DatabaseConnection {
         static Connection con;
         static Statement s;
         static ResultSet rs;
         static String driver = "com.mysql.jdbc.Driver";
         static String url = "jdbc:mysql://***.****.******/***";
         static String user = "*******";
         static String password = "********";
         static void connect() {
              try {
                   Class.forName(driver).newInstance();
                   System.out.println("Loaded Driver");
                   con = DriverManager.getConnection(url, user, password);
                   System.out.println("Connected to database\n");
                   con.setAutoCommit(false);
                   s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                             ResultSet.CONCUR_READ_ONLY);
              } catch (Throwable e) {
                   System.out.println("Error2");
                   e.printStackTrace();
         static void close() {
              try {
                   rs.close();
                   s.close();
                   con.close();
                   System.out.println("\nDisconnected From Database");
              } catch (Throwable e) {
                   System.out.println("Error1");
                   e.printStackTrace();
    }

    R.Baldwin7 wrote:
    I tried it. Still getting the same error.
    Code no looks like:
    else if (choice == 2) {
                             city = input.readUTF();
                             state = input.readUTF();
                             DatabaseConnection.connect();
                             PreparedStatement ps = DatabaseConnection.con.prepareStatement("SELECT ZipCode FROM Zipcodes "
                                       + "WHERE City = " + city + " AND State = "
                                       + state);
                             DatabaseConnection.rs = ps.executeQuery();
                             while (DatabaseConnection.rs.next()) {
                                  zipcode = DatabaseConnection.rs.getInt("ZipCode");
                                  output.writeInt(zipcode);
                                  output.flush();
    Read the API docs and the JDBC Tutorials for the proper way to use a PreparedStatement. It may "work" to add the quotes, but it is definately not the right way to do it. What happens if the city entered contains an apostrophe? Your statement will be broken again. Like I said, use a PreparedStatement and use it right.

  • Help with MySQL Form Search

    I've got a db that contains various attributes of particular
    items... very similar to a db of a DVD library, for example...
    Director, Year of Release, comments, release date... etc.
    How do I structure the query in Dreamweaver (CS3) to tell the
    db to return ALL results for a field if it is submitted blank? As
    in, if a user didn't specify a Director, then it should not filter
    by that column and return ALL directors instead?
    In the advanced recordset dialogue I have the variables set
    to submit the run-time values from the form, but I don't know what
    to put in the "Default Value" field...
    I know this should be very simple, but I just can't get it to
    work... I tried %, but that's not doing it. (also, I tried
    searching the forum, but the search function is not working
    properly right now.)
    Any help is appreciated.

    I am completely self-taught to this point... testing the
    fields for content and adjusting the WHERE clause accordingly is a
    bit beyond my level. However, if anyone knows of any good content
    on the web that can help me get it that would be helpful... i just
    need to see a couple examples of this in action in order to
    comprehend it.
    I know that this is (or should be) an incredibly basic
    function of DB query... this shouldn't be THAT hard to find... I've
    googled and come up short...

  • Help with MYSQLi Query and WHILE statement

    Hi,
    Not sure what is wrong here but the same record is printed in the while loop 11 times (the amount of records in the table).
    <?php 
    //Main Connection & Query
    //Database Connection & Error
    $con_host = 'X';
    $con_username = 'X';
    $con_password = 'X';
    $con_database = 'X';
    $con = mysqli_connect($con_host, $con_username, $con_password, $con_database);
    ?>
    <?php
    //Query
    $sql = "SELECT * FROM equipment ORDER BY name ASC";
    $query = mysqli_query($con, $sql);
    $row = mysqli_fetch_assoc($query);
    $row_count = mysqli_num_rows($query);
    //Create Variables
    $name = $row['name'];
    $size = $row['size'];
    $quantity = $row['quantity'];
    $protection = $row['protection'];
    $location = $row['location'];
    $sublocation = $row['sublocation'];
    $bc = $row['BC'];
    $id = $row['id'];
    ?>
    <!doctype html>
    <html>
    <link href="stylesheets/main_stylesheet.css" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
    <!-- Favicon -->
    <link rel="shortcut icon" type="image/png" href="images/icon.png" />
    <style type="text/css">
    </style>
    <head>
    <meta charset="utf-8">
    <title>Print Equipment List</title>
    <link href="stylesheets/print_stylesheet.css" rel="stylesheet" type="text/css">
    <script src="sorttable.js"></script>
    <!--<body onload="window.print()">-->
    </head>
    <body>
    <div class="print_button no-print" onClick="window.print()">Print</div>
    <div class="print_text no-print">Select the sorting of the list by clicking on the table categories and click the print button below</div>
    <div class="print_a4page">
      <div class="print_header">
         <div class="print_header_logo"><img src="images/logo.png" width="306" height="43"></div>
          <div class="print_header_text" id="header_text">Drama Database</div>
          <div class="print_header_info">List printed: <script type="text/javascript">
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      document.write(day + "/" + month + "/" + year);</script>
      <br>
    Total records:
    <?php echo $row_count ?></div>
      </div>
        <div class="print_header_divider">Equipment List</div>
        <div class="print_body">
          <div>
            <form name="users" method="post">
              <div class="table_print">
              <table width="100%" border="0" cellpadding="5" class="sortable">
                <tr class="table_header_print">
                  <th width="15%" scope="col">Name</th>
                  <th width="12%" scope="col">Size</th>
                  <th width="9%" scope="col">Quantity</th>
                  <th width="12%" scope="col">Protection</th>
                  <th width="17%" scope="col">Location</th>
                  <th width="12%" scope="col">Sublocation</th>
                  <th width="11%" scope="col">Barcode</th>
                  <th width="12%" scope="col">Internal ID</th>
                </tr>
                <?php do { ?>
                <tr class="table_body">
                  <td><?php echo $name ?></td>
                  <td><?php echo $size ?></td>
                  <td><?php echo $quantity ?></td>
                  <td><?php echo $protection ?></td>
                  <td><?php echo $location ?></td>
                  <td><?php echo $sublocation ?></td>
                  <td><?php echo $bc ?></td>
                  <td><?php echo $id ?></td>
                </tr>
                <?php } while ($row = mysqli_fetch_assoc($query));?>
              </table>
            </form>
          </div>
        </div>
    </div>
    </body>
    </html>

    Still getting the same issue.
    As I see it, the way you have suggested is just rearanging things right?
    here is a screenshot of the outcome:
    And here is the improved code:
    <?php 
    //Main Connection & Query
    //Database Connection & Error
    $con_host = 'X';
    $con_username = 'X';
    $con_password = 'X';
    $con_database = 'X';
    $con = new mysqli($con_host, $con_username, $con_password, $con_database);
    ?>
    <?php
    //Query
    $sql = "SELECT * FROM equipment ORDER BY name ASC";
    $result = $con->query($sql);
    $row = $result->fetch_assoc();
    $row_count = $result->num_rows;
    //Create Variables
    $name = $row['name'];
    $size = $row['size'];
    $quantity = $row['quantity'];
    $protection = $row['protection'];
    $location = $row['location'];
    $sublocation = $row['sublocation'];
    $bc = $row['BC'];
    $id = $row['id'];
    ?>
    <!doctype html>
    <html>
    <link href="stylesheets/main_stylesheet.css" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
    <!-- Favicon -->
    <link rel="shortcut icon" type="image/png" href="images/icon.png" />
    <style type="text/css">
    </style>
    <head>
    <meta charset="utf-8">
    <title>Print Equipment List</title>
    <link href="stylesheets/print_stylesheet.css" rel="stylesheet" type="text/css">
    <script src="sorttable.js"></script>
    <!--<body onload="window.print()">-->
    </head>
    <body>
    <div class="print_button no-print" onClick="window.print()">Print</div>
    <div class="print_text no-print">Select the sorting of the list by clicking on the table categories and click the print button below</div>
    <div class="print_a4page">
      <div class="print_header">
         <div class="print_header_logo"><img src="images/logo.png" width="306" height="43"></div>
          <div class="print_header_text" id="header_text">Drama Database</div>
          <div class="print_header_info">List printed: <script type="text/javascript">
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      document.write(day + "/" + month + "/" + year);</script>
      <br>
    Total records:
    <?php echo $row_count ?></div>
      </div>
        <div class="print_header_divider">Equipment List</div>
        <div class="print_body">
          <div>
            <form name="users" method="post">
              <div class="table_print">
              <table width="100%" border="0" cellpadding="5" class="sortable">
                <tr class="table_header_print">
                  <th width="15%" scope="col">Name</th>
                  <th width="12%" scope="col">Size</th>
                  <th width="9%" scope="col">Quantity</th>
                  <th width="12%" scope="col">Protection</th>
                  <th width="17%" scope="col">Location</th>
                  <th width="12%" scope="col">Sublocation</th>
                  <th width="11%" scope="col">Barcode</th>
                  <th width="12%" scope="col">Internal ID</th>
                </tr>
                <?php while ($row = $result->fetch_assoc()) { ?>
                <tr class="table_body">
                  <td><?php echo $name ?></td>
                  <td><?php echo $size ?></td>
                  <td><?php echo $quantity ?></td>
                  <td><?php echo $protection ?></td>
                  <td><?php echo $location ?></td>
                  <td><?php echo $sublocation ?></td>
                  <td><?php echo $bc ?></td>
                  <td><?php echo $id ?></td>
                </tr>
                <?php } ?>
              </table>
            </form>
          </div>
        </div>
    </div>
    </body>
    </html>

  • Some help with MySQL fetch size

    To get the number of rows returned by a MySQL query, I do this:
    public static void main(String[] args) throws Exception
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection connection = DriverManager.getConnection(url, user, password);
            Statement statement = connection.createStatement();
            String query = "SELECT * FROM users";
            ResultSet rs = statement.executeQuery(query);
            int number = statement.getFetchSize();
            connection.close();
            System.out.print(number);
        }which returns 0 even though I have 7 users. What am I doing wrong?

    Jamwa wrote:
    Sad to say but
    Retrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object. Is a bit ambiguous to me.When trying to look something up in the API, it's a good idea to keep your eyes open. I scrolled up half a screen
    from getFetchSize to setFetchSize, and Lo! and behold:
    <quote>
    If the fetch size specified is zero, the JDBC driver ignores the value and is free to make its own best guess as to
    what the fetch size should be. The default value is set by the Statement object that created the result set.
    </quote>
    Now I understand what a fetch size of 0 means. Thank you, API!

  • OT: Help with MySQL/PHP line (SQL syntax)

    I have this now -
    $colname_rsPassword = $_POST['password'];
    $query_rsPassword = sprintf("SELECT contactFName,
    contactLName,
    contactPassword, contactEmail, contactRecord FROM
    tblcontactdata WHERE
    contactPassword = %s", GetSQLValueString($colname_rsPassword,
    "text"));
    How would I change that to include $_POST['LName'] and
    $_POST['FName'] (as
    posted from the form) in the WHERE clause?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================

    I did it another way -
    GetSQLValueString($colname_rsPassword, "text"),
    $_POST['fname'],
    $_POST['lname']);
    goes to this -
    GetSQLValueString($colname_rsPassword, "text"),
    "'".$_POST['fname']."'",
    "'".$_POST['lname']."'");
    Woiks!
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Joe Makowiec" <[email protected]> wrote in
    message
    news:[email protected]..
    > On 11 Oct 2006 in macromedia.dreamweaver.appdev, Murray
    *ACE* wrote:
    >
    >> SELECT contactFName, contactLName, contactPassword,
    contactEmail,
    >> contactRecord FROM tblcontactdata WHERE
    contactPassword =
    >> 'uwUYreTTM' AND contactFName = Murray AND
    contactLName = Summers
    >
    > That might be the problem. Try adding the quotes to the
    string:
    >
    > $query_rsPassword = sprintf("SELECT contactFName,
    contactLName,
    > contactPassword, contactEmail, contactRecord FROM
    tblcontactdata WHERE
    > contactPassword = %s AND contactFName = '%s' AND
    contactLName = '%s'",
    > GetSQLValueString($colname_rsPassword, "text"),
    $_POST['fname'],
    > $_POST['lname']);
    >
    > --
    > Joe Makowiec
    >
    http://makowiec.net/
    > Email:
    http://makowiec.net/email.php

Maybe you are looking for