MySQL /JDBC Question

I began playing with JDBC a few days ago. I set up a database using mySQL and wrote a simple java program that will connect to it. Works good from the computer that holds the database.
I try and run the same program from my secondary computer which does not have mySQL or ODBC mySQL drivers, I get com.mysql.jdbc.Driver for an error message. (Trying to access the database on my main computer via ip/databasename)
My Question is, do you HAVE to have mySQL or Connector/ODBC installed on a computer if you wish to connect to a database on other computer??
Here's where it prints the error message...
try
Class.forName("com.mysql.jdbc.Driver");
catch (Exception e)
JOptionPane.showMessageDialog(null, "ERROR = " + e.getMessage());
I use this as my url..
private final String url = "jdbc:mysql://122.122.122.122:3306/test123";
     

Say I want to make a simple web applet that will
access a database on my computer. The only way my
vistors to my website will be able to access the
database via the web applet is by having mySQL JDBC
driver installed on their computers?yes.
however.
you can package up the JDBC driver as part of your jar with your applet so it doesn't require the user to "install" anything. it's just part of your applet.

Similar Messages

  • Error : class not found exception : com.mysql.jdbc.driver in Eclipse Tool

    Hi
    I have impoted project file in eclipse in new machine using option import from existing workbence . When i stat to debug this project ,
    i am getting error as class not found exception : com.mysql.jdbc.driver . my project folder already consist of mysql .jar file in /web appls/web-inf folder.
    Application is running successfully in other machine from where i took the application file. As this error appeared I also added jar file into project path as Project ---->properties-- build java path---libraries----add external jar file.
    kindly hep me.

    Sounds like an eclipse question - not a JDBC one.
    But since eclipse is telling you it can't find it then it means it is not in the eclipse path. So you must add it. (The fact that it is somewhere is irrelevant - all that matters is it is not in the class path.)

  • Error in Class.forName("com.mysql.jdbc.driver")

    Hi forum,
    Please help me to solve the issue.
    im using the following jsp code for genrating the reports using JASPER REPORTS
    the JSP FILE
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="javax.sql.DataSource"%>
    <%@ page import="javax.naming.InitialContext"%>
    <%@ page import="net.sf.jasperreports.engine.*"%>
    <%@ page import="net.sf.jasperreports.engine.design.JasperDesign"%>
    <%@ page import="net.sf.jasperreports.engine.xml.JRXmlLoader"%>
    <%@ page import="net.sf.jasperreports.engine.export.*" %>
    <%@ page import ="net.sf.jasperreports.engine.*"%>
    <%@ page import ="net.sf.jasperreports.engine.JasperFillManager"%>
    <%@ page import ="net.sf.jasperreports.engine.JRException"%>
    <%@ page import="net.sf.jasperreports.engine.JasperReport"%>
    <%@ page import="net.sf.jasperreports.engine.JasperPrint"%>
    <html>
    <body bgcolor="00ffcc">
    <%
    try{
    Connection con = null;
    String url="jdbc:mysql://localhost/customer";
    String username = "root";
    String password = "cmsadmin";
    InputStream input=new FileInputStream(new File("C:/Documents and Settings/user/My Documents/NetBeansProjects/jasperreports/web/helloworld.xml"));
    JasperDesign design = JRXmlLoader.load(input);
    JasperReport report = JasperCompileManager.compileReport(design);
    Map params = new HashMap();
    params.put("reportTitle", "helloworld");
    params.put("author", "Muthu Kumar");
    params.put("startDate", (new java.util.Date()).toString());
    params.put("ReportTitle", "PDF JasperReport");
    <img class="emoticon" src="images/emoticons/confused.gif" border="0" alt="" />Class.forName("com.mysql.jdbc.Driver");<img class="emoticon" src="images/emoticons/confused.gif" border="0" alt="" /><img src="images/emoticons/confused.gif" border="0" alt="" />
    con = DriverManager.getConnection(url,username,password);
    JasperPrint print = JasperFillManager.fillReport(report, params, con);
    OutputStream output=new FileOutputStream(new File("C:/Documents and Settings/user/My Documents/NetBeansProjects/jasperreports/helloreportworld.pdf"));
    JasperExportManager.exportReportToPdfStream(print, output);
    // JasperViewer.viewReport(print);
    catch(SQLException es) {
    out.println(es);
    catch(JRException ex){
    //ex.printStackTrace();
    out.println(ex);
    %>
    </body>
    </html>The error it is saying is in the line Class.forName(....) ;
    Please look for the emoctions with question mark
    i DOn know what to do.
    Please help
    Im comparin the below JRXML file as with the above code
    <?xml version="1.0"?>
    <!DOCTYPE jasperReport
    PUBLIC "-//JasperReports//DTD Report Design//EN"
    "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
    <jasperReport name="helloworld">
    <parameter name="reportTitle" class="java.lang.String"/>
    <parameter name="author" class="java.lang.String"/>
    <parameter name="startDate" class="java.lang.String"/>
    <queryString>
    <![CDATA[SELECT * FROM customer order by UserID ]]>
    </queryString>
    <field name="UserID" class="java.lang.String"/>
    <field name="UserName" class="java.lang.String"/>
    <field name="City" class="java.lang.String"/>
    <field name="State" class="java.lang.String"/>
    <title>
    <band height="60">
    <textField>
    <reportElement x="0" y="10" width="500" height="40"/>
    <textElement textAlignment="Center">
    <font size="24"/>
    </textElement>
    <textFieldExpression class="java.lang.String">
    <![CDATA[$P{reportTitle}]]>
    </textFieldExpression>
    </textField>
    <textField>
    <reportElement x="0" y="40" width="500" height="20"/>
    <textElement textAlignment="Center"/>
    <textFieldExpression class="java.lang.String">
    <![CDATA["Run by: " + $P{author}
    + " on " + $P{startDate}]]>
    </textFieldExpression>
    </textField>
    </band>
    </title>
    <columnHeader>
    <band height="30">
    <rectangle>
    <reportElement x="0" y="0" width="500" height="25"/>
    <graphicElement/>
    </rectangle>
    <staticText>
    <reportElement x="5" y="5" width="50" height="15"/>
    <textElement/>
    <text><![CDATA[UserID]]></text>
    </staticText>
    <staticText>
    <reportElement x="55" y="5" width="150" height="15"/>
    <text><![CDATA[UserName]]></text>
    </staticText>
    <staticText>
    <reportElement x="205" y="5" width="255" height="15"/>
    <text><![CDATA[City, State]]></text>
    </staticText>
    </band>
    </columnHeader>
    <detail>
    <band height="20">
    <textField>
    <reportElement x="5" y="0" width="50" height="15"/>
    <textElement/>
    <textFieldExpression class="java.lang.String">
    <![CDATA[$F{UserID}]]>
    </textFieldExpression>
    </textField>
    <textField>
    <reportElement x="55" y="0" width="150" height="15"/>
    <textElement/>
    <textFieldExpression class="java.lang.String">
    <![CDATA[$F{UserName}]]>
    </textFieldExpression>
    </textField>
    <textField>
    <reportElement x="205" y="0" width="255" height="15"/>
    <textElement/>
    <textFieldExpression class="java.lang.String">
    <![CDATA[$F{City} + ", " + $F{State}]]>
    </textFieldExpression>
    </textField>
    </band>
    </detail>
    </jasperReport>

    Glass_Fish wrote:
    I have set the classpath in the environment variables in the my computer properties.The web container has it's own properties. The "system" classpath means absolutely nothing to it. Read your server's documentation.

  • MySQL JDBC & RMI

    I have been developing a project, in which I have a Remote Object(RMI) which returns a ResultSet object obtained by MySql JDBC(J-Connector).
    The problem is the ResultSet object does not implement the Serializable Interface so that it cannot be passed to the client site from the remote site through RMI. This is fine, I have other way of solving this, except it will reduce my performance quite a lot!
    Therefor, I am wondering how does MYSQL JDBC does this...
    I can run a client in one machine and a DB (say MySQL)on the other machine. Using JDBC to connect them, and I can get the ResultSet with no problem at all, this resultset is also remote somehow. My question is how does MYSQL JDBC handle this, so that the data get passed from one mechine to another, and the speed is really fast....
    An answer will be a great value to me. Thanks in advance...

    JDBC connects to the Database not to a Java RMI server. You cannot pass a ReultSet around like this. They retain a connection to the Database (usually) until all rows have been and then still (usually) until closed. For this reason alone, it would be impossible to pass around ResultSets in this manner, and I am sure there are other reasons.

  • Newbie with JSP & JDBC questions

    Hi. I have a quick question. I have a client jsp page with a table, listing all the fields from my mySQL table called kellybclients. At the end of each row, I also have a submit button that I would like navigate the user to the campus jsp page that only shows the data associated with the client who's button they clicked on in the table. I'm trying to figure out how to pass this data from my JSP into the rowset.setCommand method in my connection/data bean. I am using a cached row set. Here's the code from my bean:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package ETS;
    import java.sql.SQLException;
    import javax.sql.rowset.CachedRowSet;
    import java.util.ArrayList;
    import com.sun.rowset.CachedRowSetImpl;
    public class CampusDataBean {
        private CachedRowSet rowSet;
      public CampusDataBean() throws Exception
        Class.forName("com.mysql.jdbc.Driver");
        rowSet = new CachedRowSetImpl();
        rowSet.setUrl("jdbc:mysql://traderseven.nmsu.edu/is470Spring08?relaxAutoCommit=true");
        rowSet.setUsername("is470Spring08");
        rowSet.setPassword("1DoNtier");
        rowSet.setCommand("SELECT campid, clientid, campname,campcounty FROM kellybCampus WHERE clientid=?");
        CampusBean camp = new CampusBean();
        rowSet.setString(1, camp.getClientID());
        rowSet.execute();
      public ArrayList<CampusBean> getCampusList() throws SQLException
        ArrayList<CampusBean> campusList = new ArrayList<CampusBean>();
        rowSet.beforeFirst();
        while(rowSet.next())
          CampusBean campus = new CampusBean();
          campus.setCampID(rowSet.getString(1));
          campus.setClientID(rowSet.getString (2));
          campus.setCampName(rowSet.getString(3));
          campus.setCounty(rowSet.getString(4));
          campusList.add(campus);
        return campusList;
    public void addCampus(CampusBean campus) throws SQLException
        rowSet.moveToInsertRow();
        rowSet.updateString(1,campus.getCampID());
        rowSet.updateString(2,campus.getClientID());
        rowSet.updateString(3,campus.getCampName());
        rowSet.updateString(4,campus.getCounty());
        rowSet.insertRow();
        rowSet.moveToCurrentRow();
        rowSet.acceptChanges();
    }I'm sorry if this is too vague. I'd appreciate any help, fixes, or pointers on where to learn how to do this. Thank you again.
    KellyJo

    So the button should be a Submit button for a form. There are a couple of different methods for doing this:
    1) Each row on the table can be a different form, each form uses the same action (servlet) target and has a hidden input with a unique identifier for each of the clients:
    <table>
      <tr><form action="selectClient" method="post"><td> etc </td><td><input type="hidden" name="id" value="1"/><input type="submit"/></td></form></tr>
      <tr><form action="selectClient" method="post"><td> etc </td><td><input type="hidden" name="id" value="2"/><input type="submit"/></td></form></tr>2) Use a single form with a button type=submit for each row with different values (Note: This is broken in IE7 so you probably shouldn't use it)
    <table><form action="selectClient" method="post">
      <tr><td> etc </td><td><button type="submit" name="id" value="1">Submit</button></td></tr>
      <tr><td> etc </td><td><button type="submit" name="id" value="2">Submit</button></td></tr>3) Use a single form, have a hidden value with a blank value. Each row has a submit button with a javascript onclick method that sets the form's hidden value to one appropriate to the row, then submits the form. I won't show you this code but there are examples on the web.
    4) Use a single form with an input="submit" element on each row. Each button would have a different name with the ID info encoded in it, then you would have server-side code that takes parameters, finds the right one and parses out the proper row to edit:
    <table><form action="selectClient" method="post">
      <tr><td> etc </td><td><input type="submit" name="submit__id_1"/></td></tr>
      <tr><td> etc </td><td><input type="submit" name="submit__id_2"/></td></tr>I think most people end up doing some variant of 3, which I don't like because I hate to rely on JavaScript to make my web apps work properly. I would prefer 4, which takes more work on the server side (which I like better) but 1 works just as well with a lot more typing and uglier HTML code. Actually, I would like 2 the best because that is pretty much what the <button> element was designed for, but Microsoft screwed that up.

  • MySQL JDBC Performance Issues

    Hi, First off, let me admit, im a java newbie. I've been using java for about 6 months now, although im a fast learner, some things still elude me.
    I've searched these forums and google high and low for an answer to my question before signing up and posting here, so i'm kind of at my wits end.
    Let me explain my specs so noone blames lack of power for this issue.
    System specs:
    Linux Cent OS 4 2.6.19 SMP
    JRE 1.6
    MySQL 4.2.2 ICC Compiled Enterprise Edition
    4x HyperThreaded Xeon 1.9Ghz cpus (Displays as 8)
    16GB ECC Double-Parity Double-Buffered Memory. (Rediculous IBM proprietary memory)
    Problem:
    I first wrote this application in PHP as it my stong suit (that should tell you plenty). But the PHP CLI was eating up way to much CPU power/MySQL bandwith to execute this script, and taking way to long, so i started re-writing it in C++, well when my feeble C++ powers failed me, i went to Java. I know more Java then C++ but i picked C first because i thought it would be the fastest. Java, however, is slower then PHP when i write the identical logic, i dont know if i should blame Java or my assumption that i can copy logic from one language to another.
    Here is the details:
    I have 1 MySQL database and 2 Tables im pulling from, This mysql database is optimized by the people from MySQL, so i know its not the DB, Server, or Tables. 1 table (bfpax) has around 45k rows (45000), the second table (bfbdet) has around 100k rows (100000). What this program has to do, its objective, is:
    1. Pull the indexed ID from table 1;
    2. With that ID, pull other data from table 2 and table 1 for each ID;
    3. Compile that data together for each ID
    4. Insert compiled data into a HEAP table for fast access for each ID.
    In PHP (pseudocode):
    SELECT ID FROM bfpax;
    Loop:
    Foreach id pull various data pieces i.e. name, client code, address, zip, etc.
    String format name: "A-GARY/COLE" becomes "Gary/Cole"
    String format hotel: "ACUNMIP" becomes CUNMIP
    Insert all formatted/fixed data into heap table
    End loop.
    In Java (pseudocode):
    SELECT ID FROM cpax;
    Loop:
    Create object with ID as constructor variable (see below for object declaration) and add to an arrayList;
    End Loop;
    Create 6 threads to execute each of the objects methods for data collection/formatting
    Start each thread using inner classes to loop through the object arraylist and execute dedicated methods per thread.
    Thread 1: Pull air data
    Thread 2: Pull destination
    Thread 3: Pull hotel
    Thread 4: Pull gateway
    Thread 5: Pull the rest (price, dates, etc)
    Thread 6: Start executing the update method
    The above kind of failed, so i reduced the complexity by nuking the whole thread idea and now i just have a simple function that loops through the arraylist of objects and executes each method in order.
    Booking Object:
    public class Booking extends ReportingConstants{
        private ArrayList<String> myData = new ArrayList<String>();
        private int myBookNum;
        private static Connection myCon;
        public static int numBookings;
        public int updateCount = 0;
        public boolean isFinished = false;
        public Booking(int booking_number, Connection conn) {
            if (booking_number > 9999) {
                myBookNum = booking_number;
            numBookings++;
            myCon = conn;
            //Run loop to make sure myData has the proper spaces for insert, ensureCapacity didnt work.
            for (int i = 0; i < 15; i++) {
                myData.add("");
            myData.set(_BOOKNUM,String.valueOf(myBookNum));
            if (Integer.valueOf(_ARGS[_DEBUG][1]) > 0) {
                System.out.println("Initialized booking number "+myBookNum+" count "+numBookings);
        public void getAir() {
            ResultSet res;
            ArrayList<String> total_air = new ArrayList<String>();
            String airlines = "";
            String query = "SELECT operator_id FROM EDITED.bfbdet WHERE record_type = 'A' AND item_desc LIKE '-%' AND booking_number = "+myBookNum+" AND operator_id IS NOT NULL";
            if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
                System.out.println("Starting Air: "+query);
            res = MySQL.sqlQuery(query,myCon,5);
            try {
                while(res.next()) {
                    if (res.getString(1).length() > 1) {
                        String id = res.getString(1).substring(0,2);
                        if (!total_air.contains(id)) {
                            airlines += id+",";
                        total_air.add(id);
                res.close();
                MySQL.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            myData.set(_AIR,airlines);
            updateCount++;
        public void getDest() {
            String query = "SELECT booking_code FROM EDITED.bfpax WHERE booking_number = "+myBookNum+" LIMIT 1";
            ResultSet res;
            String isSv ="Y";
            String dest;
            if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
                System.out.println("Starting Dest: "+query);
            res = MySQL.sqlQuery(query,myCon,1);
            try {
                while (res.next()) {
                    dest = res.getString(1).substring(1,4);
                    if (dest != "FRE") {
                        if (dest == "GYY") {
                            String realDest = res.getString(1).substring(4,2);
                            if (realDest == "GY") {
                                dest = "GYY";
                            } else if (realDest == "MC") {
                                dest = "MCO";
                            } else if (realDest == "FL") {
                                dest = "FLL";
                            } else if (realDest == "IW") {
                                dest = "IWA";
                            } else if (realDest == "PI") {
                                dest = "PIE";
                            } else if (realDest == "LA") {
                                dest = "LAS";
                            } else {
                                dest = "GYY";
                        } else {
                            isSv = "N";
                        myData.set(_DEST,dest);
                        myData.set(_SV,isSv);
                        updateCount++;
                res.close();
                MySQL.close();
            } catch (Exception ex) {
                ex.printStackTrace();
        public void getGateway() {
            String query = "SELECT item_desc FROM EDITED.bfbdet WHERE (booking_number = '"+myBookNum+"' OR booking_number = ' "+myBookNum+"') AND item_desc LIKE '-%' ORDER BY booking_suffix ASC LIMIT 1";
            if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
                System.out.println("Starting GW: "+query);
            ResultSet res = MySQL.sqlQuery(query,myCon,1);
            String gw;
            try {
                while (res.next()) {
                    gw = res.getString(1).substring(1,3);
                    myData.set(_GW,gw);
                updateCount++;
                res.close();
                MySQL.close();
            } catch (Exception ex) {
                ex.printStackTrace();
        public void getHotel() {
            String query = "SELECT operator_id FROM EDITED.bfbdet WHERE record_type = 'H' AND (booking_number = '"+myBookNum+"' OR booking_number = ' "+myBookNum+"') LIMIT 1";
            if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
                System.out.println("Starting Hotel: "+query);
            ResultSet res = MySQL.sqlQuery(query,myCon,1);
            String hotel = "";
            try {
                while (res.next()) {
                    hotel = res.getString(1).substring(0,6);
                    if (myData.get(_DEST) == "") {
                        myData.set(_DEST,res.getString(1).substring(0,3));
                        updateCount++;
                myData.set(_HOTEL,hotel);
                updateCount++;
                res.close();
                MySQL.close();
            } catch (Exception ex) {
                ex.printStackTrace();
        public void getRest() {
            String query = "SELECT client_code, passenger1_name, agentid, booked_date, dep_date, total_price, total_received, total_commission, number_pax FROM EDITED.bfpax WHERE booking_number = "+myBookNum+" LIMIT 1";
            if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
                System.out.println("Starting Rest: "+query);
            ResultSet res = MySQL.sqlQuery(query,myCon,1);
            try {
                while (res.next()) {
                    myData.set(_AGENCY,res.getString(1));
                    if (res.getString(3) != "null") {
                        myData.set(_AGENT,res.getString(3));
                    } else {
                        myData.set(_AGENT,"");
                    myData.set(_PAXNAME,res.getString(2).replace("'",""));
                    myData.set(_BKDATE,String.valueOf(res.getDate(4)));
                    myData.set(_DEPDATE,String.valueOf(res.getDate(5)));
                    myData.set(_TPRICE,String.valueOf(res.getDouble(6)));
                    myData.set(_TRECV,String.valueOf(res.getDouble(7)));
                    myData.set(_TCOM,String.valueOf(res.getDouble(8)));
                    myData.set(_NUMPAX,String.valueOf(res.getInt(9)).trim());
                    //System.out.println("NUMPAX: |"+myData.get(_NUMPAX)+"|");
                updateCount++;
                res.close();
                MySQL.close();
            } catch(Exception ex) {
                ex.printStackTrace();
        public void storeData() {
            if (!isFinished) {
                String query = "INSERT INTO "+tmpTable+" (`booking_number`, `destination`, `gateway`, `airline`, `hotel`, `agency`, `agent`, `booked_date`, `dep_date`, `total_price`, `total_received`, `total_commission`, `number_pax`, `passenger_name`, `is_skyvalue`) VALUES('"+myData.get(0)+"','"+myData.get(1)+"','"+myData.get(2)+"','"+myData.get(3)+"','"+myData.get(4)+"','"+myData.get(5)+"','"+myData.get(6)+"','"+myData.get(7)+"','"+myData.get(8)+"','"+myData.get(9)+"','"+myData.get(10)+"','"+myData.get(11)+"','"+myData.get(12)+"','"+myData.get(13)+"','"+myData.get(14)+"')";
                if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
                    System.out.println(query);
                MySQL.sqlExec(query,myCon);
                isFinished = true;
                if (Integer.valueOf(_ARGS[_DEBUG][1]) > 0) {
                    System.out.println("Booking number "+myBookNum+" is finished!");
            } else {
                //System.out.println("Not fully populated!");
    }Please dont laugh too hard heh, i know my code is sloppy and probably not optimized at all, i dont pretend to be a hardcore java guy, but i would love to learn. Im also posting below my static MySQL class so you can see what happens when i call sqlQuery();
    public abstract class MySQL {
        private static ResultSet res;
        private static Statement stmt;
        public static ResultSet sqlQuery(String query,Connection con, int limit) {
            try {
                stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                stmt.setFetchSize(limit);
                res = stmt.executeQuery(query);
            } catch(Exception ex) {
                ex.printStackTrace();
                res = null;
                System.out.println("Cant Query!: "+query);
            return res;
        public static void sqlExec(String query,Connection con) {
            Statement stmt;
            try {
                stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                stmt.executeUpdate(query);
                stmt.close();
            } catch(Exception ex) {
                ex.printStackTrace();
                System.out.println("Cant Query!: "+query);
        public static void close() {
            try {
                stmt.close();
                res.close();
            } catch (Exception ex) {
                ex.printStackTrace();
    }If you notice, i require the connection to be passed when executing a query, i do this because even if i made a static connection state in the MySQL class, for some reason, it still gets duplicated every time its called. This way, i create 1 connection with the calling static main class, and pass that same conn back and forth through the whole script. I know in PHP this is the best way to do it, in Java it may require many different connections.
    By the way, this is an update that runs once per hour, it does not have to worry about users or anything like that, it gets executed by cron on the hour.
    PHP does this job of updating about 40000 entries in 9-12 minutes. for an average of 0.0135 seconds per entry, Java rolls around at 0.06 seconds per query, 6x slower, this puts execution time at about 40 minutes, obviously this is an issue if its supposed to run every hour. The java app does not tax the system, on top/htop it does not even make it to the first page so its not resources, ive looked at the verbose gc info, and i didnt see anything to clue me in there either.
    I'm sure this is a simple error and my lack of knowledge with Java is what's holding me back, but if i cant figure this out ill have to go back to struggling with C++.
    Thanks in advance, and im sorry for the horribly long post.
    Thanks,
    Dave

    I didnt want to include this in the original post, so here is where my main is located:
    public class ReportingUpdate extends ReportingConstants {
        private ArrayList bookings;
        private static String[] argList;
        private static ArrayList<String> provArg = new ArrayList<String>();
        public ArrayList notDone = new ArrayList();
        private static Connection conn;
        public int bookingsUpdated;
        public static boolean isUpdating = false;
        private static int _ERRORS = 0;
        public static ArrayList doneBookings = new ArrayList();
        public static void main(String[] args) {
            if (args.length > 0) {
                if (args[0].contains("-help")) {
                    printHelp();
                } else {
                    setupArgs();
                    argList = args;
                    parseArgs();
            if (_ERRORS == 0) {
                new ReportingUpdate().go();
            } else {
                return;
        private static void parseArgs() {
            for (String s : argList) {
                if (s.indexOf("-") != 0) {
                    printHelp();
                    break;
                if (s.length() > 2) {
                    provArg.add(s.substring(1,2));
                } else {
                    printHelp();
                    break;
            for (int i = 0; i < _ARGS.length; i++) {
                if (provArg.contains(_ARGS[0])) {
    int pos = provArg.indexOf(_ARGS[i][0]);
    ReportingConstants._ARGS[i][1] = argList[pos].substring(2);
    //Commented out argument testing loop.
    /*for (String[] s : _ARGS) {
    System.out.println("Arg: "+s[0]+" Value: "+s[1]);
    _ERRORS++;*/
    public static void printHelp() {
    System.out.println("\nReporting Update 1.1 (2007 February 1, compiled Feb 19 2007 11:12:24)");
    System.out.println("");
    System.out.println("Usage: java -jar /path/to/ReportingUpdate.jar [arguments]");
    System.out.println("");
    System.out.println("Arguments:");
    System.out.println(" -d<level>\tDebug Level: 0-No Output(Default), 1-Start and finish output, 2-Functional Output(Lots of output)");
    System.out.println(" -l<limit>\tBooking Limit. How many bookings will be updated, only use this for testing.");
    System.out.println(" -a<0,1> \tBool choice to run the air update function, speed testing option. (0-0ff,1-On)\n \t\tIf this is not set, on is assumed");
    System.out.println(" -e<0,1> \tSame as above, but for destination.");
    System.out.println(" -g<0,1> \tSame as above, but for gateway.");
    System.out.println(" -h<0,1> \tSame as above, but for hotel.");
    System.out.println(" -r<0,1> \tSame as above, but for agency,agent,price & dates.");
    System.out.println(" -u<0,1> \tSame as above, but for each bookings actual insert into the db.");
    System.out.println("");
    System.out.println("Example: java -jar /path/to/ReportingUpdate.jar -d1 -l500 -a0 -d0 -u0");
    System.out.println("Run the reportingupdate with debug level 1, limit 500 bookings and do not run the air, destination or insert functions.\n");
    _ERRORS++;
    public void go() {
    String limitString;
    if (Integer.valueOf(_ARGS[_LIMIT][1]) > 0) {
    limitString = "LIMIT "+_ARGS[_LIMIT][1];
    } else {
    limitString = "";
    bookings = new ArrayList();
    ResultSet res;
    connect();
    res = MySQL.sqlQuery("SELECT booking_number FROM EDITED.bfpax WHERE booking_number IS NOT NULL "+limitString,conn,Integer.valueOf(_ARGS[_LIMIT][1]));
    try {
    int i = 0;
    while (res.next()) {
    String booking = res.getString("booking_number");
    booking = booking.trim();
    if (booking.length() > 1) {
    //System.out.println("Reading booking "+booking);
    bookings.add(new Booking(Integer.valueOf(booking),conn));
    i = 1;
    startTheFire();
    } catch(Exception ex) {
    ex.printStackTrace();
    private void startTheFire() {
    /*Thread a = new Thread(new DoAir());
    Thread b = new Thread(new DoDest());
    Thread c = new Thread(new DoGW());
    Thread d = new Thread(new DoHotel());
    Thread e = new Thread(new DoRest());
    Thread f = new Thread(new DoUpdate());
    a.setName("Air");
    a.start();
    b.setName("Dest");
    b.start();
    c.setName("GW");
    c.start();
    d.setName("Hotel");
    d.start();
    e.setName("Rest");
    e.start();
    f.setName("Update");
    f.start();
    try {
    f.sleep(20000);
    } catch (Exception ex) {
    ex.printStackTrace();
    Iterator it = bookings.iterator();
    while (it.hasNext()) {
    Booking b = (Booking) it.next();
    if (Integer.valueOf(_ARGS[_AIRARG][1]) > 0) {
    b.getAir();
    if (Integer.valueOf(_ARGS[_DESTARG][1]) > 0) {
    b.getDest();
    if (Integer.valueOf(_ARGS[_GWARG][1]) > 0) {
    b.getGateway();
    if (Integer.valueOf(_ARGS[_HOTELARG][1]) > 0) {
    b.getHotel();
    if (Integer.valueOf(_ARGS[_RESTARG][1]) > 0) {
    b.getRest();
    if (Integer.valueOf(_ARGS[_UPDATEARG][1]) > 0) {
    b.storeData();
    class DoAir implements Runnable {
    public void run() {
    Iterator it = bookings.iterator();
    while(it.hasNext()) {
    Booking tempBooking = (Booking) it.next();
    tempBooking.getAir();
    if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
    System.out.println("Air is done!");
    class DoDest implements Runnable {
    public void run() {
    Iterator it = bookings.iterator();
    while(it.hasNext()) {
    Booking tempBooking = (Booking) it.next();
    tempBooking.getDest();
    if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
    System.out.println("Dest is done!");
    class DoGW implements Runnable {
    public void run() {
    Iterator it = bookings.iterator();
    while(it.hasNext()) {
    Booking tempBooking = (Booking) it.next();
    tempBooking.getGateway();
    if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
    System.out.println("Gateway is done!");
    class DoHotel implements Runnable {
    public void run() {
    Iterator it = bookings.iterator();
    while(it.hasNext()) {
    Booking tempBooking = (Booking) it.next();
    tempBooking.getHotel();
    if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
    System.out.println("Hotel is done!");
    class DoRest implements Runnable {
    public void run() {
    Iterator it = bookings.iterator();
    while(it.hasNext()) {
    Booking tempBooking = (Booking) it.next();
    tempBooking.getRest();
    if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
    System.out.println("The Rest is done!");
    class DoUpdate implements Runnable {
    public void run() {
    while (bookingsUpdated <= Booking.numBookings) {
    if (doneBookings.size() > 0) {
    isUpdating = true;
    Iterator it = doneBookings.iterator();
    while (it.hasNext()) {
    Booking b = (Booking) it.next();
    b.storeData();
    bookingsUpdated++;
    it.remove();
    isUpdating = false;
    if (Integer.valueOf(_ARGS[_DEBUG][1]) > 1) {
    System.out.println("Update is done!");
    private void connect() {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection(_URL,_USER,_PASS);
    } catch(Exception ex) {
    System.out.println("Cannot Connect to: "+_URL);
    ex.printStackTrace();
    createTempTable();
    private void createTempTable() {
    String create_query = "CREATE TABLE IF NOT EXISTS `"+tmpTable+"` (`ID` INT( 5 ) NOT NULL AUTO_INCREMENT ,`booking_number` INT( 6 ) NULL ,`destination` CHAR( 3 ) NULL ,`gateway` CHAR( 3 ) NULL ,`airline` VARCHAR( 15 ) NULL ,`hotel` CHAR( 6 ) NULL ,`agency` VARCHAR( 15 ) NULL ,`agent` VARCHAR( 20 ) NULL ,`booked_date` VARCHAR( 10 ) NULL ,`dep_date` VARCHAR( 10 ) NULL ,`total_price` VARCHAR( 10 ) NULL ,`total_received` VARCHAR( 10 ) NULL ,`total_commission` VARCHAR( 10 ) NULL ,`number_pax` INT( 5 ) NULL ,`passenger_name` VARCHAR( 50 ) NULL,`is_skyvalue` CHAR( 1 ) NULL,PRIMARY KEY ( `ID` ),INDEX ( `booking_number` ),INDEX ( `agency` ) ) TYPE = memory;";
    String trunc = "TRUNCATE TABLE `"+tmpTable+"`";
    MySQL.sqlExec(create_query,conn);
    MySQL.sqlExec(trunc,conn);

  • Com.mysql.jdbc.PacketTooBigException when creating a DB Table resource

    Hellos.
    I am trying to add an Oracle Database Table resource to my IDM 6.0 system.
    On the the last screen of the wizard, when I save my details, I see this error in red:
    ==> com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1340540 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
    I have a mysql repository and use Tomcat 4.1 (on Windows).
    Questions...
    What file do I edit?
    Do I add this parameter.. if so what value do I use?
    Who else has seen this?
    thanks.. GF

    You need to change "my.ini" file for MySQL, usualy it is in windows folder.
    Change the value of 'max_allowed_packet' in my.ini file to some thing like 16M.
    I hope it helps..
    --Vipul                                                                                                                                                                                                                                                                                                                                                                           

  • Basic JDBC Question

    Okay, I think this isn't supposed to be in this forum (Seeing as how there's a JDBC forum and all..), but this is so basic and I'm kicking myself over it I thought I'd put it in here. Anyways:
    I just installed mysql-connector-java-2.0.14, or at least I think I did. I keep getting the "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" error. I read a lot of the forum hits I got for the error, but none of them helped me out...
    My JDK (I'm using 1.3.1_06 for compatibility reasons) is installed to /usr/java/jdk
    I'm compiling an applet on one machine, but hosting it off another. The applet must then be viewed by the compiling machine, the hosting machine, and any other machines (which I do not have access to).
    My question is this: What the hell am I doing wrong. :) Am I not understanding applets right? Does the client viewing it have to have the mysql driver installed? Does the server need it? I would assume only the compiling computer would...
    And if I only need it on the compiling machine, what am I doing wrong? My environmental variables are set as shown, I'm compiling with the shown command, and the code snippets are from my stuff. Parts in bold are what I feel is relevent (in the paths). God I feel like an idiot...
    Thanks in advance, and sorry to waste your time...
    echo $PATH
    /bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/home/jcourts/bin:/usr/java/jdk/bin:/usr/java/jdk/jre/lib/ext:/usr/java/jdk/jre/lib/ext/mysql-connector-java-2.0.14-bin.jar
    echo $CLASSPATH
    /usr/java/jdk/jre/lib/ext:/usr/java/jdk/jre/lib/ext/mysql-connector-java-2.0.14-bin.jar
    echo $JAVA_HOME
    /usr/java/jdk
    /usr/java/jdk/bin/javac -g -deprecation *.java
    import java.sql.*;
    -and-
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://<<host_is_here>>/<<db_name>>?user=<<username>>");

    Hvae program to test the ODBC or JDBC Bridge and driver, so that you know you've set it up right. I gave up on applets ages ago for this sort of thing, though I do know you have to install a seperate driver for applets, perhaps someone could come in on this and guide you more
    This will teat your driver and set-up, so compile and run this code;-
    import java.sql.*;
    import java.util.*;
    public class MyConnection
         Connection con;
         MyConnection()
              try
    // ******************************Connected To Jdbc-Odbc Type - 1 Driver
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //               con = DriverManager.getConnection("Jdbc:Odbc:dsnname","userid","password");
                   con = DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};Server=servername;Database=pubs","userid","password");
    // ******************************Connected To Ms-Access JDBC ODBC Driver .
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   con = DriverManager.getConnection("Jdbc:Odbc:dsnname","","");
    //               con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=G:/admin.mdb","","");
    // ******************************Connected To Ms-Access Type-3 Driver.
         /*          Class.forName ("acs.jdbc.Driver");
                   String url = "jdbc:atinav:servername:5000:C:\\admin.mdb";
                   String username="Admin";
                   String password="";
                   Connection con = DriverManager.getConnection(url,username,password);
    // ******************************Connected To Microsoft SQL.
                   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                   con = DriverManager.getConnection("jdbc:microsoft:sqlserver://servername:1433","userid","password");
    // ******************************Connected To Merant.
                   Class.forName("com.merant.datadirect.jdbc.sqlserver.SQLServerDriver");
                   con = DriverManager.getConnection("jdbc:merant:sqlserver://servername:1433;User=userid;Password=password");
    // ******************************Connected To Atinav SqlServer.
                   Class.forName ("net.avenir.jdbc2.Driver");
                   con= DriverManager.getConnection("jdbc: AvenirDriver://servername:1433/pubs","userid","password");
    // ******************************Connected To J-Turbo.
    /*               String server="servername";
                   String database="pubs";
                   String user="userid";
                   String password="password";
                   Class.forName("com.ashna.jturbo.driver.Driver");
                   con= DriverManager.getConnection("jdbc:JTurbo://"+server+"/"+database,user,password);
    /*// ******************************Connected To jk Jdbc Driver.
                   String url= "jdbc:jk:server@pubs:1433";
                   Properties prop = new Properties();
                   prop.put("user","userid");//Set the user name
                   prop.put("password","password");//Set the password
                   Class.forName ("com.jk.jdbc.Driver").newInstance();
                   con = DriverManager.getConnection (url, prop);*/
    // ******************************Connected To jNetDirect Type - 4 Driver
    /*               String sConnect = "jdbc:JSQLConnect://127.0.0.1/database=pubs&user=userid&password=password";
                   Class.forName ("com.jnetdirect.jsql.JSQLDriver").newInstance();     
                   Connection con= DriverManager.getConnection(sConnect);
    // ******************************Connected To AvenirDriver Type - 4 Driver
    //               String url= "jdbc: AvenirDriver: //servername:1433/pubs";
    //               java.util.Properties prop = new java.util.Properties ();
    //               prop.put("user","userid");
    //               prop.put("password","password");
    /*               Class.forName ("net.avenir.jdbc2.Driver");     
                   System.out.println(" Connected To AvenirDriver Type - 4 Driver");
                   con= DriverManager.getConnection("jdbc: AvenirDriver://servername:1433/pubs","userid","password");
    // ******************************Connected To iNet Sprinta2000 Type - 4 Driver
         /*          String url="jdbc:inetdae7:servername:1433";
                   String login="userid";
                   String password="password";
                   Class.forName("com.inet.tds.TdsDriver");
                   System.out.println(" Connected To iNet Sprinta2000 Type - 4 Driver");
                   con=DriverManager.getConnection(url,login,password);
    // ******************************Connected To iNet Opta2000 Type - 4 Driver
    /*               String url="jdbc:inetdae7:servername:1433";
                   String login="sagar";
                   String password="sagar";
                   Class.forName("com.inet.tds.TdsDriver").newInstance();
                   System.out.println(" Connected To iNet Opta2000 Type - 4 Driver");
                   con=DriverManager.getConnection(url,login,password);
                   DatabaseMetaData md = con.getMetaData();
                   System.out.println("Driver Name            " + md.getDriverName());
                   System.out.println("Driver Version         " + md.getDriverVersion());
                   System.out.println("Database URL is        " + md.getURL());
                   System.out.println("Database UserName is   " + md.getUserName());
                   System.out.println("Connection Name        " + md.getConnection());
                   System.out.println("Database Name          " + md.getDatabaseProductName());
                   System.out.println("Database Version       " + md.getDatabaseProductVersion());
                   System.out.println("Database ReadOnly Type " + md.isReadOnly());
                   System.out.println("MaxColumnNameLength    " + md.getMaxColumnNameLength());
                   System.out.println("MaxConnections         " + md.getMaxConnections());
                   System.out.println("");
              catch(ClassNotFoundException cnfe)
                   System.out.println(cnfe.getException());
                   System.out.println("The Specified Driver Does not Exist....");
              catch(SQLException sqle)
                   if(sqle.getErrorCode() == 0)
                        System.out.println("No Suitable Driver Found..");
                   else if(sqle.getErrorCode() == 1017)
                        System.out.println("Wrong UserName Or Password..");
                   else if(sqle.getErrorCode() == 1034)
                        System.out.println("Database not Started..");
                        System.out.println(sqle.getErrorCode());
                        System.out.println(sqle.getSQLState());
                        System.out.println(sqle);
         public static void main (String args[])
              new MyConnection();
    }

  • Difficulty Installing the MySQL JDBC Driver

    I am trying to install mySQL JDBC driver "mysql-connector-java-2.0.14.tar.gz" to link up with the mySQL server on a Windows XP OS.
    The error is:
    Cannot find database driver classes
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    I have read the USAGE AND INSTALLATION in the README file, but it can not seem to find these drivers still. I added the location to my PATH variable in the environment variables, and set CLASSPATH= ... as well and still can not find them
    Paths i added to PATH and CLASSPATH variables
    C:\j2sdk1.4.0_01\mysqlconnector.tar
    C:\j2sdk1.4.0_01\JDBC
    I did both methods it suggested, within the JDBC folder are the com and org folders. Anyone offer some suggestions.
    I know some smart person is going to say just use linux, but it is needed for my father and he can barely use MS Windows.
    Cheers for any help

    Dear Java Newsgroup User
    I would like to understand more around the Java and MySQLJDBC Configuration. Because I have some problem trying to install and Testing the MySQL JDBC Connector Driver.
    I use Windows XP Professional.
    I Downloaded and Intalled Sun One Studio to start learning JAVA and Features. This SDK Package make 3 Packages (directories):
    Directory No1 C:\JSDK4\j2sdk1.4.1_02 (JAVA_HOME)
    Directory No2 C:\JSDK4\s1studio (Source Examples ...)
    Directory No3 C:\Archivos de programa\Java\j2re1.4.1_02 (Java R. Env.)
    In the WINDOWS XP PANNEL CONTROL apper Java Plugins Control Pannel also
    when I press or click this icon apper a Java Screen where i can see the following Configuration in the Advanced Option:
    Java RuntTime Enviroment:
    Use Java Plugin Default
    JRE 1.4.1_02 in C:\Archivos de programa\Java\j2re1.4.1_02
    SDK 1.4.1_02 in C:\JSDK4\j2sdk1.4.1_02
    MySQL Driver Confiration and Version:
    This is my Un-ziped MySQL JDBC connector Path:
    C:\JSDK4\j2sdk1.4.1_02\mysql-connector-java-3.0.8-stable
    Into mysql-connector-java-3.0.8-stable directory exist an directory called [testsuite] that have some jar, java and class files.
    Testing MySQL JDBC Connecto Driver and Error Message:
    When i try to run the BaseTestCase.class file the system give me the following ERROR Message:
    C:\JSDK4\j2sdk1.4.1_02\mysql-connector-java-3.0.8-stable\testsuite>java BaseTestCase
    Exception in thread "main" java.lang.NoClassDefFoundError: BaseTestCase (
    ame: testsuite/BaseTestCase)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.
    3)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    My Question are the following:
    1- What is the meaning of this message error?
    2- What i need to do to solve this problem?
    3- What is the function specificly of the JRE 1.4.1_02 in C:\Archivos de programa\Java\j2re1.4.1_02 Directory in My JAVA Instalation.
    I you need more detail of my instalation please write me and i write back a soon as possible.
    Dear Users:
    Please Help Me! to continue with the next steps ...
    Best Regards and Than's so much for read this message
    From Panama City
    VanyRon

  • Help with com.mysql.jdbc.Driver

    Hi all
    I am new to working with java. I am working off of my laptop (pc -vista) and
    am trying to connect to a database on a server I have, mac osx 10.x.
    First question: I would install com.mysql.jdbc.Driver on the same server as
    the MySql server correct?
    Second and more important question: I have multiple pages
    printed out on installing this driver but I just cannot follow it. I am not
    very good in terminal(mac) and the install seems terminal based.
    Can someone please try to explain to me in laymen terms what needs to
    be done?
    thanks alot
    Marcus

    marcusam wrote:
    sorry for my lack of knowledge
    client code = all on one machine?No, client code = the code you use to access your DB server.
    >
    I wanted to access a database that was on a totally different machine, with a java application.
    is this not very doable - or realistic?
    It's completely doable.
    i found enviroment variables for CLASSPATH that are pointing inside 'jre1.6.0_07'
    but i also have 'jdk1.6.0_07' - should the development kit be the one i use? - sorry
    back to original question - so would i just move the .jar file into
    \jre1.6.0_02\lib\ext\ or something of that sort
    thanks alot
    MarcusYes, you can move the jar into the ext directory if you wish. How are you running your java application? What are you typing/clicking on?

  • Why my MySQL JDBC Connect fail??

    Dear friends:
    I have following code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class JdbcExample2 {
      public static void main(String args[]) {
        Connection con = null;
        try {
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          //jdbc:mysql://host_name:port/dbname
    //     con = DriverManager.getConnection("jdbc:MySQL:///test","admin", "admin");
          con = DriverManager.getConnection("jdbc:MySQL://localhost:3306/test","admin", "admin");
          if(!con.isClosed())
            System.out.println("Successfully connected to " +
              "MySQL server using TCP/IP...");
        } catch(Exception e) {
          System.err.println("Exception: " + e.getMessage());
        } finally {
          try {
            if(con != null)
              con.close();
          } catch(SQLException e) {}
    }But when I run , I got following error:
    Exception: com.mysql.jdbc.Driver
    My question is:
    [1]. when I connect to MySQL Server through mySQL Client, I got
    Enter password: *****
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 18 to server version: 4.1.21-community-nt
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    mysql>
    how Can I determine MySQL Server name?? I forgot when I install, maybe MySQL is my SQL Server name
    [2]. Do I need to creat a user DSN name or System DSN name for MySQL Server?? which one is best??
    How to do it??
    [3]. How to make above simple JDBC program runnable??
    Thanks
    sunny
    Message was edited by:
    sunnymanman

    Thanks, see new errors:
    C:\Project\java>java Jdbc11
    Copyright 2004, R.G.Baldwin
    java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:868)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3340)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1238)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2743)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:512)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at Jdbc11.main(Jdbc11.java:23)
    C:\Project\java>
    any idea??
    here Jdbc11.java:23 is:
    Connection con = DriverManager.getConnection(
    url,"admin", "YES");
    my userID/Password = admin/admin;
    sunny
    Message was edited by:
    sunnymanman

  • Cannot import com.mysql.jdbc.exceptions

    Hi all,
    I have a pretty simple question.
    Why it is not possible to import classes from the package com.mysql.jdbc.exceptions?
    My classpath is set up correctly I can use jdb driver to connect to my db, but if I try to import com.mysql.jdbc.exceptions I receive a compile time error
    package com.mysql.jdbc.exceptions does not exist!
    Anyone could help?
    Thanks for your attention
    By Manio

    Thankfully there is no reason for you to do this so it's really not a problem.
    You should ONLY be importing java.sql.* (and sometimes javax) but not specific driver packages.

  • MYSQL JDBC NoClassDefFoundError: org/aspectj/lang/Signature

    i am trying to connect to a database via java using JDBC i have installed:
    jdk1.5.0_01
    mysql-connector-java-3.1.8-bin-g.jar
    MySQL Server 4.1
    Java works fine, MYSQL works fine from the command prompt but when it comes to testing using this simple java program
    public class JdbcExample1 {
    public static void main(String args[]) {
    Connection con = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("localhost", "username", "password");
    if(!con.isClosed())
    System.out.println("Successfully connected to MySQL server...");
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    } finally {
    try {
    if(con != null)
    con.close();
    } catch(SQLException e) {}
    this compiles fine but when run i get the following error message
    Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at JdbcExample1.main(JdbcExample1.java:10)
    class path is set as .;C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext\mysql-connector-java-3.1.8-bin.java
    any help or input on this error would be appreciated
    thanks in advanced Neil

    Hi, All:
    I just read this thread of discussion and got valueable info to solve my problem in a similar fashion. I'd suggest the last poster, Anil, to re-read the whole thread to correct the possible problems stated.
    I would just like to add my problem/solution scenario to this thread to share my experience. I assume that readers already went through the previous notes in this thread.
    #1. Space in Path:
    I installed
    MySQL DB server in: "C:\Program Files\MySQL\MySQL Server 4.1"
    MySQL JDBC Driver: D:\mysql\mysql-connector-java-3.1.8
    It seems to me that the DB server installed directory is not affected by whether there is a space in path name. The JDBC Driver path, on the other hand, does have the side effect of the space in path name when accessing by the Java client.
    #2. -g in JDBC Driver:
    I have been using the driver mysql-connector-java-3.1.8-bin.jar. However, right before I needed to create my ant build.xml configuration file (more details later), I thought the instruction asked me to use the mysql-connector-java-3.1.8-bin-g.jar (the debug version as kpreiser indicated), and therefore I got the now-well-known "org/aspectj/lang/Signature" error. After I removed that "-g" from the JDBC driver extression in my build.xml file, it then works well. (Great tip, kpreiser.)
    #3. Middlegen with Hibernate:
    My situation is a bit more complicated, but the issue of "org/aspectj/lang/Signature" error was the same (finally resolved in #2). I was trying to use Middlegen to re-generate my Hibernate map files from the data schema. (Hibernate is an open source tool that lets you create JavaBean source file from a Hibernate map file to map to a database table (see http://www.hibernate.org/ for more details.) Since I re-factored my data schema in the database, I needed to re-generate the Hibernate map files (from data schema) so that I can in turn use the map files to re-generate the JavaBean code. I wanted to use the Middlegen tool (see http://www.hibernate.org/98.html for more details) to re-generate the map files from database schema. However, in order to use Middlegen properly, you need to create the ant build.xml file to do that job. So I had to resort to MiddlegenIDE (see http://ultimania.org/middlegenide/ for more details) to help generate that build.xml file. (This is where I had the -g specified for the JDBC driver in the build.xml file that caused the problem.) Once that build.xml file is generated, the use of ant (a Java make tool) with the build.xml file can generate the hibernate map files. From these map files, JavaBean source files can be generated using Hibernate CodeGenerator.hbm2java tool. (There are several other useful tools in Hibernate too to convert the database ddl schema and the JavaBean source file.)
    Obviously, there are other approaches and tools that you can use (XDoclet for instance) for different situations, but I am only providing a high level overview on what you can do to be more productive if you are involved in a large and complicated project with Java/JDBC and ORM (Object/Relational Mapping).
    Item #3 may sound complicated at first, but it's worth the time to learn the tools and concept. Once you are familiar with these tools (Eclipse, Hibernate, Middlegen, Ant, etc.), you will become more productive in responding to the dynamic nature of the high-tech world where changing requirements are the only constant. I hope that these separate tools will become more integrated and easier to use in the future, but for now they do the job well.
    Thanks for the great tips and hope that this helps too.
    - Shuh

  • Connection mysql jdbc error ?

    I have program java likes this :
    import java.sql.*;
    public class LoadDriver {
        // Define the JDBC Driver and the database connection URL
        public static final String DRIVER = "com.mysql.jdbc.Driver";
        public static final String URL = "jdbc:mysql://localhost/java?user=test&password=test";
        public static void main(String args[]) {
            Connection conn = null;
    Statement select = null;
    ResultSet result = null;
            try {
                // load the driver dynamically
                Class.forName(DRIVER);
                // connect to the database
                conn = DriverManager.getConnection(URL);
                // perform a query. first create a Statement object from the connection
                select = conn.createStatement();
    // next execute a query (SQL string) and return the results in a ResultSet object
                result = select.executeQuery("select fname, lname from names order by lname, fname");
                // print out the results
                while(result.next()) {
                    String fname = result.getString("fname"); // note these match the columns in the
                    String lname = result.getString("lname"); // SELECT statement (fname, lname)
                    System.out.println(fname+" "+lname);
    // check if there was a problem executing the SQL statement
            catch (SQLException e) {
                System.err.println("SQL Exception: "+e.getMessage());
                System.exit(1);
    // if the JDBC driver is not in the CLASSPATH
            catch (ClassNotFoundException e) {
                System.err.println("Class not found:  "+e.getMessage());
                System.exit(1);
    // catch any other exceptions
            catch (Exception e) {
                System.err.println("Other Exception: ");
                System.err.println(e.getMessage());
                System.exit(1);
    // You want to close the connections no matter what happens!
    finally {
    try {
    // close the result, query, and database connection
    if (result != null) result.close();
                 if (select != null) select.close();
                if (conn != null) conn.close();
    catch (SQLException e) {
    // one of the new cases where it's OK to just eat exceptions or at the most log them
    System.err.println("Error closing connection: "+e.getMessage());
      but i get errror likes this :
    D:\Program Files\Java\jdk1.5.0_03\bin>javac LoadDriver.java
    D:\Program Files\Java\jdk1.5.0_03\bin>java LoadDriver
    Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Sign
    ature
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at LoadDriver.main(LoadDriver.java:20)
    D:\Program Files\Java\jdk1.5.0_03\bin>
    I place mysql.jar in
    - D:\Program Files\Java\jdk1.5.0_03\jre\lib\ext
    - D:\Program Files\Java\jdk1.5.0_03\lib
    - D:\Program Files\Java\jdk1.5.0_03\jre\lib
    and i make classpath to D:\Program Files\Java\jdk1.5.0_03\bin;D:\Program Files\Java\jdk1.5.0_03\jre\lib\ext\
    but it still doesn't work
    What must I do ?
    Thx 4 your reply

    Hello!
    I'm getting this same error message and i followed the code example as close as i could:
    Thanks for any help on this!
    bk
    set oldpath=%PATH%
    set JAVA_HOME=C:\jdk1.5.0_02
    set ANT_HOME=C:\ANT\apache-ant-1.6.5
    set PATH=C:\jdk1.5.0_02\bin;%ANT_HOME%\bin
    set CLASSPATH=.;C:\jdk1.5.0_02\lib;C:\MYSQL\mysql-connector-java-3.1.10\src\com\;C:\MYSQL\mysql-connector-java-3.1.10\src\org\;C:\MYSQL\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin-g.jar;
    http://www.developer.com/java/data/article.php/3417381#Critical_steps_in_using_JDBC
    import java.sql.*;
    public class Jdbc11 {
      public static void main(String args[]){
        System.out.println(
                      "Copyright 2004, R.G.Baldwin");
        try {
          Statement stmt;
          //Register the JDBC driver for MySQL.
          Class.forName("com.mysql.jdbc.Driver");
          //Define URL of database server for
          // database named mysql on the localhost
          // with the default port number 3306.
          String url =
                "jdbc:mysql://localhost:3306/mysql";
          //Get a connection to the database for a
          // user named root with a blank password.
          // This user is the default administrator
          // having full privileges to do anything.
          Connection con =
                         DriverManager.getConnection(
                                     url,"root", "");
          //Display URL and connection information
          System.out.println("URL: " + url);
          System.out.println("Connection: " + con);
          //Get a Statement object
          stmt = con.createStatement();
          //Create the new database
          stmt.executeUpdate(
                           "CREATE DATABASE JunkDB");
          //Register a new user named auser on the
          // database named JunkDB with a password
          // drowssap enabling several different
          // privileges.
          stmt.executeUpdate(
              "GRANT SELECT,INSERT,UPDATE,DELETE," +
              "CREATE,DROP " +
              "ON JunkDB.* TO 'auser'@'localhost' " +
              "IDENTIFIED BY 'drowssap';");
          con.close();
        }catch( Exception e ) {
          e.printStackTrace();
        }//end catch
      }//end main
    }//end class Jdbc11
    Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Signature

  • Unable to create : com.mysql.jdbc.Driver error with JDeveloper 10.1.3

    Hi all,
    I got this error when I tried to execute a simple JSF app. I am using JDeveloper 10.1.3 release edition. Please advice
    [Starting OC4J using the following ports: HTTP=8988, RMI=23891, JMS=9227.]
    **** Unable to obtain password from principals.xml. Using default.
    C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\config>
    C:\JDeveloper10g\jdk\bin\javaw.exe -ojvm -classpath C:\JDeveloper10g\j2ee\home\oc4j.jar;C:\JDeveloper10g\jdev\lib\jdev-oc4j-embedded.jar -Xverify:none -DcheckForUpdates=adminClientOnly -Doracle.application.environment=development -Doracle.j2ee.dont.use.memory.archive=true -Doracle.j2ee.http.socket.timeout=500 -Doc4j.jms.usePersistenceLockFiles=false oracle.oc4j.loader.boot.BootStrap -config C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\config\server.xml
    [waiting for the server to complete its initialization...]
    2006-01-31 21:40:47.062 NOTIFICATION Auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\dms.war...
    2006-01-31 21:40:47.093 NOTIFICATION Unjar C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\dms.war in C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\dms
    2006-01-31 21:40:47.093 NOTIFICATION Finished auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\dms.war
    2006-01-31 21:40:47.156 NOTIFICATION Auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\connectors\datasources\datasources.rar...
    2006-01-31 21:40:47.156 NOTIFICATION Unjar C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\connectors\datasources\datasources.rar in C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\connectors\datasources\datasources
    2006-01-31 21:40:47.171 NOTIFICATION Finished auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\connectors\datasources\datasources.rar
    2006-01-31 21:40:47.218 NOTIFICATION Auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j.ear...
    2006-01-31 21:40:47.281 NOTIFICATION Unjar C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j.ear in C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j
    2006-01-31 21:40:47.359 NOTIFICATION Finished auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j.ear
    2006-01-31 21:40:47.375 NOTIFICATION Auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j\webapp.war...
    2006-01-31 21:40:47.375 NOTIFICATION Unjar C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j\webapp.war in C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j\webapp
    2006-01-31 21:40:59.296 NOTIFICATION Finished auto-unpacking C:\JDeveloper10g\jdev\system\oracle.j2ee.10.1.3.36.73\embedded-oc4j\applications\bc4j\webapp.war
    2006-01-31 21:41:08.421 WARNING J2EE OJR0107 Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
    06/01/31 21:41:08 SEVERE: ApplicationStateRunning.initConnector Error occurred initializing connectors. Exception is: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
    Jan 31, 2006 9:41:08 PM com.evermind.server.ApplicationStateRunning initConnector
    SEVERE: Error occurred initializing connectors. Exception is: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
    06/01/31 21:41:08 SEVERE: ApplicationStateRunning.initConnector Stack trace: oracle.oc4j.sql.DataSourceException: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
         at com.evermind.server.ApplicationStateRunning.initDataSourceConnectionPool(ApplicationStateRunning.java:2016)
         at com.evermind.server.ApplicationStateRunning.initDataSourceConnector(ApplicationStateRunning.java:1961)
         at com.evermind.server.ApplicationStateRunning.initConnector(ApplicationStateRunning.java:1220)
         at com.evermind.server.ApplicationStateRunning.initConnectors(ApplicationStateRunning.java:356)
         at com.evermind.server.ApplicationStateRunning.initializeApplication(ApplicationStateRunning.java:208)
         at com.evermind.server.Application.setConfig(Application.java:391)
         at com.evermind.server.Application.setConfig(Application.java:309)
         at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:1771)
         at com.evermind.server.ApplicationServer.initializeDeployedApplications(ApplicationServer.java:1532)
         at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:939)
         at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:113)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: javax.resource.ResourceException: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
         at oracle.oc4j.sql.spi.ResourceAdapterImpl.createDataSourceConnectionPool(ResourceAdapterImpl.java:106)
         at oracle.oc4j.sql.DataSourceUtils.getDataSourceConnectionPool(DataSourceUtils.java:322)
         at com.evermind.server.ApplicationStateRunning.initDataSourceConnectionPool(ApplicationStateRunning.java:1997)
         ... 11 more
    Caused by: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
         at oracle.oc4j.sql.config.DataSourceConfigUtils.createConnectionFactory(DataSourceConfigUtils.java:247)
         at oracle.oc4j.sql.DataSourceConnectionPoolImpl.<init>(DataSourceConnectionPoolImpl.java:107)
         at oracle.oc4j.sql.spi.ResourceAdapterImpl.createDataSourceConnectionPool(ResourceAdapterImpl.java:99)
         ... 13 more
    Caused by: oracle.classloader.util.AnnotatedClassNotFoundException:
         Missing class: com.mysql.jdbc.Driver
         Dependent class: oracle.oc4j.sql.config.DataSourceConfigUtils
         Loader: oc4j:10.1.3
         Code-Source: /C:/JDeveloper10g/j2ee/home/lib/oc4j-internal.jar
         Configuration: <code-source> in META-INF/boot.xml in C:\JDeveloper10g\j2ee\home\oc4j.jar
    This load was initiated at current-workspace-app.root:0.0.0 using the Class.forName() method.
    The missing class is not available from any code-source or loader in the system.
         at oracle.classloader.PolicyClassLoader.handleClassNotFound(PolicyClassLoader.java:2061)
         at oracle.classloader.PolicyClassLoader.internalLoadClass(PolicyClassLoader.java:1665)
         at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1621)
         at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1606)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:242)
         at oracle.oc4j.sql.config.DataSourceConfigUtils.createConnectionFactory(DataSourceConfigUtils.java:244)
         ... 15 more
    Jan 31, 2006 9:41:08 PM com.evermind.server.ApplicationStateRunning initConnector
    SEVERE: Stack trace: oracle.oc4j.sql.DataSourceException: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
         at com.evermind.server.ApplicationStateRunning.initDataSourceConnectionPool(ApplicationStateRunning.java:2016)
         at com.evermind.server.ApplicationStateRunning.initDataSourceConnector(ApplicationStateRunning.java:1961)
         at com.evermind.server.ApplicationStateRunning.initConnector(ApplicationStateRunning.java:1220)
         at com.evermind.server.ApplicationStateRunning.initConnectors(ApplicationStateRunning.java:356)
         at com.evermind.server.ApplicationStateRunning.initializeApplication(ApplicationStateRunning.java:208)
         at com.evermind.server.Application.setConfig(Application.java:391)
         at com.evermind.server.Application.setConfig(Application.java:309)
         at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:1771)
         at com.evermind.server.ApplicationServer.initializeDeployedApplications(ApplicationServer.java:1532)
         at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:939)
         at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:113)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: javax.resource.ResourceException: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
         at oracle.oc4j.sql.spi.ResourceAdapterImpl.createDataSourceConnectionPool(ResourceAdapterImpl.java:106)
         at oracle.oc4j.sql.DataSourceUtils.getDataSourceConnectionPool(DataSourceUtils.java:322)
         at com.evermind.server.ApplicationStateRunning.initDataSourceConnectionPool(ApplicationStateRunning.java:1997)
         ... 11 more
    Caused by: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
         at oracle.oc4j.sql.config.DataSourceConfigUtils.createConnectionFactory(DataSourceConfigUtils.java:247)
         at oracle.oc4j.sql.DataSourceConnectionPoolImpl.<init>(DataSourceConnectionPoolImpl.java:107)
         at oracle.oc4j.sql.spi.ResourceAdapterImpl.createDataSourceConnectionPool(ResourceAdapterImpl.java:99)
         ... 13 more
    Caused by: oracle.classloader.util.AnnotatedClassNotFoundException:
         Missing class: com.mysql.jdbc.Driver
         Dependent class: oracle.oc4j.sql.config.DataSourceConfigUtils
         Loader: oc4j:10.1.3
         Code-Source: /C:/JDeveloper10g/j2ee/home/lib/oc4j-internal.jar
         Configuration: <code-source> in META-INF/boot.xml in C:\JDeveloper10g\j2ee\home\oc4j.jar
    This load was initiated at current-workspace-app.root:0.0.0 using the Class.forName() method.
    The missing class is not available from any code-source or loader in the system.
         at oracle.classloader.PolicyClassLoader.handleClassNotFound(PolicyClassLoader.java:2061)
         at oracle.classloader.PolicyClassLoader.internalLoadClass(PolicyClassLoader.java:1665)
         at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1621)
         at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1606)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:242)
         at oracle.oc4j.sql.config.DataSourceConfigUtils.createConnectionFactory(DataSourceConfigUtils.java:244)
         ... 15 more
    06/01/31 21:41:08 WARNING: Application.setConfig Application: current-workspace-app is in failed state as initialization failedjava.lang.InstantiationException: Error occurred initializing connectors. Exception is: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
    Jan 31, 2006 9:41:08 PM com.evermind.server.Application setConfig
    WARNING: Application: current-workspace-app is in failed state as initialization failedjava.lang.InstantiationException: Error occurred initializing connectors. Exception is: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
    2006-01-31 21:41:08.531 WARNING J2EE 0JR0013 Exception initializing deployed application: current-workspace-app. Error occurred initializing connectors. Exception is: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.mysql.jdbc.Driver
    Ready message received from Oc4jNotifier.
    Embedded OC4J startup time: 29125 ms.

    I did what Manu suggested with no success. Alternatively, I registered the driver jar with embedded OC4J preferences > global > libraries. Still does not work. Please, note, that when I run JUnit tests against my BC4J application modules with JDBC URL as connection type, everything works just fine. The problem comes while running the JSF application when the application module is using JDBC DataSource as connection type.

Maybe you are looking for