Slow mySQL select - mySQL/JDBC/CFMX issue?

Hello!
I have got two simple SQL statements in my CFMX app:
SELECT
companyname,
uidnumber,
description,
telephone
FROM
companies
WHERE
entrykey = ?
Query Parameter Value(s) -
Parameter #1(cf_sql_varchar) =
2405961E-FE08-E3BE-059C648DC01198A9
SELECT
LEFT(companyname, 250) AS companyname,
LEFT(uidnumber, 100) AS uidnumber,
LEFT(description, 250) AS description,
LEFT(telephone, 100) AS telephone
FROM
companies
WHERE
entrykey = ?
Query Parameter Value(s) -
Parameter #1(cf_sql_varchar) =
2405961E-FE08-E3BE-059C648DC01198A9
Both return the same result, but the second one only take 1
msec, the first one 30 msec. The number of chars to return (using
LEFT) is exactly the length of the field (no data is shortend).
What could be the reason for that difference? Any methods to make
query #1 as fast as query #2?
system: JDBC 5.0 / myISAM tables with UTF-8 encoding / CFMX7
app server
best regards,
Hansjoerg

Hello!
- Index exists, table is optimized (and currently has just 5
records).
- I tried to change the order, no change. The version with
the simple naming of the desired fields is always up to 10-100
times slower than the version with LEFT( ...).
- I now went back to mysql-connector-java-3.0.17-ga-bin.jar
from version mysql-connector-java-5.0.6 - now both queries have the
same speed (about 1-3 msec).
So it seems to be a JDBC driver issue but I cannot find any
information on the net why the newer version is sooo much slower.
Best regards,
Hansjoerg

Similar Messages

  • Concat java variable to a MySql select statement and exeucte

    Hi,
    I am trying to append a variable to a MySql select statement.
    Overview: I need to retrieve data from a MySql database with a java variable as a reference and select the data in the database based on that variable.
    CODE THAT I CURRENTLY HAVE:
    // Declare variables
    Connection conn = null;
    Statement st = null;
    Resultset rs2 = null;
    String st2 = null;
    String keyid = null;
    // Connect to database
    try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          st = conn.createStatement();
          // Select data in Database with hanging equal sign
          st2 = ("SELECT * FROM table WHERE keyid= ");
          // Append keyid to hanging equal sign of select statement
          rs2 = st.executeQuery(st2 + keyid);
    }This is not working when I try to display the data.

    What is not working about it? Is there an error message? Stack Trace?
    Where do you get the value of keyId from?
    I would suggest that you use a prepared statement rather than building up a sql string like this. It prevents sql injection attacks
    // Declare variables
    Connection conn = null;
    PreparedStatement stmt = null;
    Resultset rs2 = null;
    String sql= null;
    String keyid = null;
    // Connect to database
    try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          // Select data in Database with place holder for parameter
          sql = "SELECT * FROM table WHERE keyid= ?";
           // prepare the statement
          stmt = conn.prepareStatement(sql);
          // set the value of key id to use with the query
          stmt.setString(1, keyId);
          // run the query
          rs2 = st.executeQuery();
    catch (Exception e){
      System.out.println("An error occurred " + e.getMessage());
      e.printStackTrace();
    finally{
      if (rs2 != null) try { rs2.close(); } catch(SQLException ex){}
      if (stmt != null) try { stmt.close(); } catch(SQLException ex){}
      if (conn != null) try { con.close(); } catch(SQLException ex){}
    }

  • Migration workbench hangs after selecting mysql as type of database.

    Hi,
    I am trying to migrate a mysql database to oracle8.17 on linux redhat 7.2
    right after it says 'please select the type and version of database you want to migrate to oracle (where i select mysql, and click ok) , nothing happens. the jre process keeps consuming cpu, but that's it.
    I have the v1.2a of the mysql jdbc driver installed.
    the error.log doesn't show anything out of the ordinary:
    ** Oracle Migration Workbench
    ** Release 1.3.1.0.0 Production
    ** ( Build 18072000 )
    ** ORACLE_HOME: /home/oracle/product/8.1.7
    ** user language: en
    ** user region: US
    ** user timezone: ECT
    ** file encoding: ISO8859_1
    ** java version: 1.1.8
    ** java vendor: IBM Corporation
    ** o.s. arch: i586
    ** o.s. name: Linux
    ** o.s. version: #1 Thu Sep 6 17:21:28 EDT 2001.2.4.7-10
    ** Classpath:
    /home/oracle/product/8.1.7/JRE/lib/i18n.jar:/home/oracle/product/8.1.7/JRE/lib/r
    t.jar:/home/oracle/product/8.1.7/Omwb/jlib:/home/oracle/product/8.1.7:/home/orac
    le/product/8.1.7/Omwb/plugins/MySQL.jar:/home/oracle/product/8.1.7/Omwb/Drivers/
    mm.mysql.jdbc-1.2a:/home/oracle/product/8.1.7/Omwb/jlib/omwb-1_3_1_0_0.jar:/home
    /oracle/product/8.1.7/jdbc/lib/classes111.zip:/home/oracle/product/8.1.7/lib/vbj
    orb.jar:/home/oracle/product/8.1.7/jlib/ewt-swingaccess-1_1_1.jar:/home/oracle/p
    roduct/8.1.7/jlib/ewt-3_3_6.jar:/home/oracle/product/8.1.7/jlib/ewtcompat-opt-3_
    3_6.zip:/home/oracle/product/8.1.7/jlib/share-1_0_8.jar:/home/oracle/product/8.1
    .7/jlib/help-3_1_8.jar:/home/oracle/product/8.1.7/jlib/ice-4_06_6.jar:/home/orac
    le/product/8.1.7/jlib/kodiak-1_1_3.jar:/home/oracle/product/8.1.7/omwb-1_3_1_0_0
    .jar
    ** Started : Sat Apr 13 13:48:41 CEST 2002
    any ideas ?

    Hi Tom!
    We need to know more about your specific problem. Can you please contact [email protected] so that we can help you out?
    Make sure to attach your omwb.sh file (it is located in the Omwb\bin directory where you installed the Workebnch)
    thanks
    - Garry

  • Conditional Mysql select statement

    HI Folks
    can anyone point me in the right direction with a MySQL statement.
    I will try to layout my thinking here:
    I have a form with three inputs area, name and search. I am trying to write a Mysql select statement that selects records from a single table if they match the criteria. Easy for two variables but I'm lost after that.
    1. The form includes these three inputs:
    area - drop down menu (Any as default)
    name - drop down menu (Any as default)
    search box - text area (Blank as default)
    2. The form submits to itself leaving me with these three variables
    $search=$_GET['search']
    $area=$_GET['area']
    $name=$_GET['area']
    SELECT * FROM database WHERE database.description LIKE '%$search%' AND database.area LIKE '$area' AND database.name LIKE '$name'
    3. This is where I get confused. How do I get the SQL to Select everything correctly. I have tried using PHP if/else code to fix it but I end up running around in circles with six different Select statements and haven't yet got that to work.
    So I have come to the conclusion that there must be an easier way.  I see search forms with dozens of  search criteria on websites every day an d I only have 3 - so it can't be this complicated. Right?
    I know I need to start from the beginning again but can anyone let me know how to approach it before I begin?
    Cheers
    Dave

    Typically, I would build the where clause dynamically, based upon the values in your form. If the form field contains 'Any', leave it out of the where clause. So you can test each field value and either append or not to the end of the where clause.

  • MySQL Select Statement Help Required

    I am trying to generate a report in VS 2008 (C#) using a mysql select statement but cannot get it right.
    I have groups that meet on a weekly basis on different days. I want to generate a report that shows me all the members that have not attended their group where they have missed 3 meetings in a row.
    Below is the select statement I have tried but it does not give me the results I am looking for. I have tried to look at all the meetings in a 4 week period but would prefer to look at the last 3 meetings that are recorded. Some groups might not record a meeting every week. So I want to look at the last 3 recorded meetings and count each members attendance and only report on the members with more than 3 meetings missed.
    SELECT COUNT(`groupattendance`.`Attended`) AS Attendance, `smallgroupform`.`MeetingDate`, `userinfo`.`FirstName`, `userinfo`.`Surname`, `smallgroup`.`GroupName`, `groupattendance`.`Attended`, `groupattendance`.`UserID`, `groupattendance`.`GroupID`
    FROM ((`anatomy`.`groupattendance` `groupattendance`
    INNER JOIN `anatomy`.`smallgroupform` `smallgroupform` ON `groupattendance`.`FormID` = `smallgroupform`.`FormID`)
    INNER JOIN `anatomy`.`userinfo` `userinfo` ON `groupattendance`.`UserID` = `userinfo`.`UserID`)
    INNER JOIN `anatomy`.`smallgroup` `smallgroup` ON `groupattendance`.`GroupID` = `smallgroup`.`GroupID`
    WHERE (`smallgroupform`.`MeetingDate` >= DATE_SUB(CURDATE(),INTERVAL 4 WEEK) AND `smallgroupform`.`MeetingDate` <= CURDATE()) AND `groupattendance`.`Attended` = 'False'
    GROUP BY `userinfo`.`UserID`
    HAVING Attendance >= 3
    Thanks,
    Garth.

    Hi Garth,
    Seems no one can help you directly. Try googling your SQL request. Someone may be able to help you. At this point its not really a Cr problem.
    One option is to get all the data and add filtering using the record selection formula.
    Thank you
    Don

  • How to connect mySQL database with jdbc

    Who can tell me how to connect mySQL database with jdbc? Thanks

    http://onesearch.sun.com/search/developers/index.jsp?and=connect+mysql&nh=10&phr=&qt=&not=&field=title&since=&col=devforums&rf=0&Search.x=24&Search.y=16

  • MySQL:  SELECT * FROM with a Variable from an HTML form

    Hello,
    I would like to insert the variable "find" from the HTML form below in the MySQL "SELECT * FROM" query beneath it.  In other words, where the word "santafe" appears below, I would like to insert the variable "$find."  But I can't quite get it to work.  How do I do it?
    Thanks in advance,
    John
    <form action="tsearch11.php" method="post">
    <label>Enter Topic:
    <input type="text" name="find" size="55"/>
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" />
    </label>
    </form>
    Then, on tsearch11.php:
    <?
    mysql_connect("mysqlv3", "username", "password") or die(mysql_error());
    mysql_select_db("sand2") or die(mysql_error());
    $find = strip_tags($find);
    $find = trim ($find);
    $t = "SELECT * FROM santafe"; 
    $y = mysql_query($t);
    ?>

    Putting a form variable in a SQL query to look for table or column names requires an extra level of security. You need to create an array of the valid names, and check that the form variable is in that array.
    $find = get_magic_quotes_gpc() ? stripslashes($_POST['find']) : $_POST['find'];
    $find = mysql_real_escape_string(trim($find));
    // create an array of valid table names
    $tables = array('santafe', 'sanfernando', 'guadalupe');
    // check that the variable is in the permitted array
    if (in_array($find, $tables)) {
      $t = "SELECT * FROM $find"; 
      $y = mysql_query($t);
    } else {
      $error = 'Sorry, you selected an invalid table.';
    In the page itself, check whether $y exists before using it. Otherwise display the error:
    if (isset($y)) {
      // display the results
    } elseif (isset($error)) {
      echo $error;

  • LOV is slow after selecting a value its taking much time to default

    Hi,
    I have a dependent LOV. Master LOV is executing fine and its populatin into the field fastly. But Child LOV is very slow after selecting a value its taking much time to default.
    Can any one please help me if there is any way to default the value fast after selecting a value?
    Thanks,
    Mahesh

    Hi Gyan,
    Same issues in TST and PROD instances.
    In my search criteria if i get 1 record, even after selecting that value its taking much time to default that value into the field.
    Please advice. Thanks for your quick resp.
    Thanks,
    Mahesh

  • Looking Document for jdbc troubleshooting issues

    Hi,
    Can someone post links to get a good jdbc related issues and troubleshooting tools?

    WebLogic Server (WLS) Support Pattern: Investigating JDBC Issues (Doc ID 1280894.1)
    Master Note on Oracle WebLogic Server JDBC/Database/Drivers Support Patterns (Doc ID 761097.1)

  • MYSQL backup, mysql -e "FLUSH TABLES WITH READ LOCK" doesnt work

    I want to backup mysql locking tables first using flush tables with readlock, then do rsync and then unlock tables.
    I want to do it automatically using script.
    When I log in to mysql using: mysql -u root -p
    the command:
    FLUSH TABLES WITH READ LOCK;
    works and locks the tables...but when I create my.cnf with login information to mysql:
    [client]
    user=root
    password=xxx
    the command:
    mysql -e "SHOW DATABASES"
    works and shows the databases....
    but when I run this command:
    mysql -e "FLUSH TABLES WITH READ LOCK"
    it doesnt lock the tables...why?
    thanks

    Are calling the 'mysql -e' command as your user or as root? If you call it as root (typical for a backup script), then the .my.cnf file needs to be in /root instead of $HOME.
    Scott

  • Since I downloaded Mavericks, my Mac seems to be running much slower. Anyone else have similar issues?

    Since I downloaded Mavericks, my Mac seems to be running much slower. Anyone else have similar issues?

    http://support.apple.com/kb/PH13895

  • What is the difference between mysql and mysqli

    hello can any one tell me What is the difference between mysql and mysqli ? i googled but i cant find any
    Edited by: 994030 on Mar 14, 2013 3:43 PM

    Yes. they are the same.

  • What is the difference between mysql and mysql server

    Hi,
    I notice that mysql and mysql server has been used interchangeably, but are they the same thing? could somebody give a brief explanation about this?
    Many thanks.

    Yes. they are the same.

  • 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);

  • Jdbc mysql "select ... for update" and isolation level...

    Dear, I am now writing an application, in which some worker threads will get a waiting job from database (mysql) and perform the processing.
    To avoid workers getting the same job id, I have studied the topics about locks, isolation level, and something like "select ... for update".
    The storage engine being used is innoDB. Actually the problem seems solved after using "select ... for update" to get the id, but I am just curious that do I also need to care about the isolation level. It is because when I do some experiments by setting the isolation level to serializable, but NOT using "SELECT ... FOR UPDATE" (just simple select), exception something like "deadlock found and try to restart transaction" occurs. Is there any relationship between these two things? Any comments are welcome!! Thanks!!!

    ashipj wrote:
    can u plz provide me with the code (connection string). Am new to Mysql.
    And also the driver u are using.
    Thank youDon't hijack other's topics. Kindly start your own. Don't do that before you read the [Sun JDBC tutorial|http://java.sun.com/docs/books/tutorial/jdbc/index.html] and the [MySQL JDBC documentation|http://dev.mysql.com/doc/refman/5.0/en/connector-j.html].

Maybe you are looking for

  • How can I program the text fields in my email forum to have rounded corners

    How can I program the text fields in my email forum to have rounded off edges or corners.  this is the code im using. // insert code here// insert code here// prepare email field var email = sym.$("email") email.html("Enter your Email: "); inputEmail

  • Getting pdf files into ibooks?

    I have the latest version of itunes and the latest version of ibooks on my iphone when I connect my iPhone to the macbook pro There is a books tab in itunes but there is no way to add pdf files or documents to it I tried dragging and dropping and not

  • Device Error - Sense Code

    I have tried to burn a DVD using Premier 2.0. Once I got a message - Device Error - Sense Code (04 91 C0) the second time I got the same message but a different Code - (04 92 05). A Third time I got an "Unknown Error" message. After the first error,

  • Variable for Offset

    There is standard report Customer overdue Analysis in which it gives the days overdue amount.Like,0-15 days, 16-30 days,31-60 days etc. Now the clients requirement is he should be able to input the days interval as per his desire, say 0-5 days, 6-10

  • Essbase 11.1.2.2 setup

    Hi Team, For an essbase setup ( EPM 11.1.2.2) can you let me know if this architecture will work. I have not include RDBMS here. I have not seen a setup where http server and app server(websphere) on different box. Will it be a problem during EPM con