I don't get up-to-date data from mySQL with my JDBC connections

Hi all,
I have developped a server that uses 2 JDBC connections to mySQL. Those two connections are used by two different threads. Those connections are never closed. I just create a new Statement each time I want to make a query or an update, and commit after each update.
1) If I modify data on my mySQL database with the first connection (UPDATE or DELETE), then my second connection doesn't see the modifications (using SELECT).
2) And, if I use a different software to access my database on mySQL and make some modifications, my java application doesn't see the modifications in the database.
In the two cases, my java application only see the changes in the mySQL database if I close the java application and launch it again.
It's just like if a JDBC connection can see the modifications of the database it has itself made, but can't see modifications made by an other connection to the database... That sounds crazy, as most servers use connection pooling... What do I make wrong? Would you have any idea?
Many thanks !

Thank you for your answer.
But no, it isn't a commit problem. I use InnoDB bases of mySQL, I use transactions, and I call the commit() method.
For you or anybody to be able to try, I wrote some code. It creates 2 threads. The first thread write on DB and the other reads.
package Tests;
import java.sql.*;
public class SQLConnections {
    private Thread internalThread1;   
    private Thread internalThread2;
    private Connection connection1;
    private Connection connection2;
    private static String driver = "org.gjt.mm.mysql.Driver";
    private static String database = "jdbc:mysql://223.186.6.12/test";
    private static String databaseLogin = "user";
    private static String databasePassword = "password";
    public SQLConnections() {
        // The thread that writes the SGBDR
        Runnable runner = new Runnable() {
            public void run() {
                try {
                    // Launch the JDBC connection to the mySQL server.
                    Class.forName(driver).newInstance();
                    connection1 = DriverManager.getConnection (database, databaseLogin, databasePassword);
                    connection1.setAutoCommit(false);
                    synchronized ( internalThread1 ) {
                        internalThread1.sleep(10000);
                    while ( true ) {
                        Statement statement = connection1.createStatement();
                        statement.executeUpdate("INSERT INTO bike(color) VALUES('uniqueColor')");
                        connection1.commit();
                        System.out.println("                          ##### NEW LINE IN DB #####");
                        synchronized ( internalThread1 ) {
                            internalThread1.sleep(10000);
                catch (Exception e) {
                    e.printStackTrace();
        internalThread1 = new Thread(runner);
        runner = null;
        internalThread1.setPriority(Thread.NORM_PRIORITY);
        internalThread1.start();
        // The thread that reads the SGBDR.
        runner = new Runnable() {
            public void run() {
                try {
                    // Launch the JDBC connection to the mySQL server.
                    Class.forName(driver).newInstance();
                    connection2 = DriverManager.getConnection (database, databaseLogin, databasePassword);
                    connection2.setAutoCommit(false);
                    while ( true ) {
                        Statement statement = connection2.createStatement();
                        ResultSet result = statement.executeQuery("SELECT * FROM bike");
                        while ( result.next() )
                            System.out.println(result.getInt(1)+"    "+result.getString(2));                           
                        synchronized ( internalThread2 ) {
                            internalThread2.sleep(10000);
                catch (Exception e) {
                    e.printStackTrace();
        internalThread2 = new Thread(runner);
        runner = null;
        internalThread2.setPriority(Thread.NORM_PRIORITY);
        internalThread2.start();
    public static void main(String[] args) {
        new SQLConnections();
}Here is the result I get :
[greg@ns32 Tests]$ /usr/java/j2re1.4.2_06/bin/java -classpath :mysql-connector-java-3.0.9-stable-bin.jar Tests.SQLConnections
18 uniqueColor
19 uniqueColor
##### NEW LINE IN DB #####
18 uniqueColor
19 uniqueColor
##### NEW LINE IN DB #####
18 uniqueColor
19 uniqueColor
[greg@ns32 Tests]$ /usr/java/j2re1.4.2_06/bin/java -classpath :mysql-connector-java-3.0.9-stable-bin.jar Tests.SQLConnections
18 uniqueColor
19 uniqueColor
20 uniqueColor
21 uniqueColor
##### NEW LINE IN DB #####
18 uniqueColor
19 uniqueColor
20 uniqueColor
21 uniqueColor
##### NEW LINE IN DB #####
18 uniqueColor
19 uniqueColor
20 uniqueColor
21 uniqueColor
[greg@ns32 Tests]
I'm doing something stupid?????

Similar Messages

  • How to fetch data from Mysql with SSL.

    I am using jdk1.5 and mysql 5.0.
    How to fetch data from Mysql with SSL
    I am using url = jdbc:mysql://localhost/database?useSSL=true&requireSSL=true.
    It shows error. how to fetch

    I have created certificate in mysql and checked in mysql.
    mysql>\s
    SSL: Cipher in use is DHE-RSA-AES256-SHA
    but through ssl how to fetch data in java.

  • Why can't I get imessages on my iphone4 from iphones with ios8?

    Why can't I get imessages on my iphone4 from iphones with ios8?

    Send messages with your iPhone, iPad, or iPod touch - Apple Support
    iOS: Troubleshooting Messages - Apple Support

  • Need to copy CMS data base from MySQL to oracle

    Hi,
    Right now our CMS data base is My SQL and we are planning to use oracle db as CMS data base. For that we will copy all CMS tables from My SQL to oracle. But I am not sure whether we can copy My SQL db to oracle db using copy option of script cmsdbsetup.sh.
    Below are my environment details:
    ============================================
    Product: BO XI R3.1
    OS: Linux
    CMS DB: My SQL
    Aplication server: Aapche-Tomcat
    ============================================
    Let me know whether I can copy CMS My SQL data base into Oracle data base using copy option of cmsdbsetup.sh script.
    Thanks,
    Swapnil Rodge.

    hillelhalevi wrote:
    I don't have TOAD nor any other tool for querying the database.  I'm wondering how I can load a large data set from an Oracle table onto my desktop using Excel or Access or some other tool using ODBC or not using ODBC if that's possible.  I need results to be in a .csv file or something similar. Speed is what is important here.  I'm looking to load more than 1 million but less than 10 million records at once.   Thanks.
    Use Oracle's free Sql Developer
    http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html
    You can just issue a query like this
    SELECT /*csv*/ * FROM SCOTT.EMP
    Then just save the results to a file
    See this article by Jeff Smith for other options
    http://www.thatjeffsmith.com/archive/2012/05/formatting-query-results-to-csv-in-oracle-sql-developer/

  • Saving data retrieved from text file to JDBC table

    Hi,
    I would like to save data, loaded from a text file to a dataset, into an existing JDBC table.
    The documentation I found on this subject is very brief, and no matter how I tried, I couldn't succeed.
    I would appreciate any help.
    Thank you in advance

    Hi there,
    Here is an example of reading a String and a date from a text file. Once you have what you need in the Strings (or whatever) it should be easy to insert them into and SQL statement. Let me know if you need an example of this as well and I'll post it in the morning. Right now I'm off to bed :o)
    Cheers
    Mark
    import java.io.*;
    import java.util.*;
    import java.text.*;
    public class WriteTest {
    public static void main(String [] arg) throws Exception {          
       Date today = new Date();          
       String name = "";          
       SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy");          
       File myfile = new File("hello.txt");               
       // how to input     
       BufferedReader in = new BufferedReader(new FileReader(myfile));          
       String name="",
       date="";          
       boolean eof = false;          
       do {
          name = in.readLine();               
          date = in.readLine();               
          if(!(eof = (name==null || date==null)))                    
          System.out.println(name+" "+formatter.parse(date));
       while(!eof);     
    }

  • Getting just the date out of MySQL with CF8

    I have a mysql table that includes a column 'intakeDate' set to the data type of DATE. When entering, it creates a record of YYYY-MM-DD. When I query the database with Coldfusion for the date of 2004-06-10, I get the result of {ts '2004-06-10 00:00:00'}. Fine and dandy for people in my timezone, but I found that if my users are in any timezone west of Eastern, the date slips back to the day before and their 'time stamp' is 23:00:00 (or appropriate offset). How can I get Coldfusion to just return to my Flex application only the value inside the table and not its ts version with midnight attached. Again, the table is set to only DATE and not TIMESTAMP or DATETIME so there are no time values entered. Also, mind you that this is being sent to a Flex application's manage class. Since some of this information deals with shot records and medical records, date is very important.
    I tried the MySQL function of DATE but it doesn't change the output.
    <cfquery name="list" datasource="#request.dsn#">
        Select DATE(intakeDate) as intakeDate FROM pets
    </cfquery>
    RESULTS IN:
    {ts '2010-12-29 00:00:00'}   {ts '2010-11-18 00:00:00'}    {ts '2009-12-28 00:00:00'}   {ts '2009-10-03 00:00:00'}   {ts '2009-07-13 00:00:00'}   {ts '2009-10-03 00:00:00'}    {ts '2008-06-01 00:00:00'}   {ts '2008-02-09 00:00:00'}   {ts '2003-03-01 00:00:00'}
    {ts '2004-06-10 00:00:00'}   {ts '2003-03-01 00:00:00'}    {ts '2004-06-01 00:00:00'}   {ts '2001-06-01 00:00:00'}   {ts '2010-04-01 00:00:00'}   {ts '2011-04-06 00:00:00'}    {ts '2011-04-06 00:00:00'}    {ts '2004-11-01 00:00:00'}    {ts '2010-05-04 00:00:00'}, etc
    I've been googling it all day and nothing I see if working.
    Thank!

    Thanks for pointing that out. I was playing DATE_FORMAT to convert to a string
    DATE_FORMAT(p.intakeDate, '%Y-%m-%d') as intakeDate

  • Data transfer from MySQL to Oracle Urgent!

    Hi All,
    We have a table in MySQL database and we need to transfer a subset of its data over to Oracle table. The table in MySQL is big, so we created a temp table trying to do it several times. The question is, we set the the primary key column in both MySQL temp table and Oracle table ( a varchar column), when we transfered the data over using "insert into table_name select * from table_name@hsdobc", Oracle always gave the "Null value for not Null column" error, and it's only existed for one row no matter how many rows we want to transfer, but MySQL temp table has no such null value for the primary key column, it's very strange. Anyone knows what the problem might be? Thanks very much in advance.

    Hi, thanks for your answer. I checked the MySQL table again, and found that in both the original table and the temp table, there is a row with the primary key column value "null". Don't know what happened? Probably it's a MySQL bug.
    It's not Primary Key NULL value. If your new Oracle Table has ANY column defined
    NOT NULL and while inserting you have at least one value in one row of coming data is NULL - It will fail. You need either to drop NOT NULL constraint for that
    column(s), or provide value for it.
    Also you can drop that NOT NULL constraint, Insert your data as is,
    Update your data to get rid off all NULLs and put NOT NULL constraint back on.
    ALTER TABLE MY_NEW_TABLE MODIFY MY_NEW_COLUMN NULL;
    UPDATE MY_NEW_TABLE SET MY_NEW_COLUMN = 'Some_Value';
    ALTER TABLE MY_NEW_TABLE MODIFY MY_NEW_COLUMN NOT NULL;

  • Data Extraction From HR with Delata Update fro Payroll

    Hi All,
    this is Chava,i got a problem with HR Data.Already i did Full Update,Delta Initialization but after that They did some changes in HR Cluster tables and they extracted Data from R/3 in to BW WIth Functional Module.
      Now the problem is Delta Update is not completing.
    I need to do any Extract Structure activation and how?
    Please help me, its a very big problem.
    Thanks
    Chava

    Hi Chava,
    Let me give you some points on 0HR_PY_1 .
    This datasource is Delta Supported and it can be used to load data in ODS as well as Infocube as the request gaurentees serialisation.
    As per your requirement,first do a Init Delta with out data transfer and then load selective repair requests for the rest of the data . When the delta initialization is done successfully then you can see your datasource in RSA7 . But you have indicated that your collegues have changed the Cluster tables( you mean to say as the HR Payroll data gets stored here) ,I dont have a clue as how this happens as the standard extractor doesnt mind at the changes in the data at base tables .
    But make sure you do a successful initalization.
    You have mentioned that you have done a FULL UPDATE ,Delete that request and then do a Init Load then you can have the delta loads.
    Hope it Helps..
    Thanks,
    Krish
    *Assigning Points is the best way to say thanks in SDN

  • I can't connect to Internet anymore (WIFI or Ethernet). This was working perfectly before. I don't get a proper IP address from my ADSL box and it seems there is a DNS error when accessing the Internet.

    I have an issue with my MacBook pro (MAC OS X 10.8.3) when trying to access Internet. I am behind an ADSL box (Orange). I have a PC on the same LAN which accesses Internet perfectly via the same Box.
    On the MAC, I have tried WIFI and Ethernet. And have same issue on both. I have checked the IP address (the ADSL box is a DHCP server) but the MAC doesn't get a proper IP and network mask I tried a manual IP address setup and it doesn't get better. I have setup the DNS servers for my Internet provider, but I get DNS error. I have tried 2 Internet browsers (Chrome and Safari), both have the same issue.
    I tried to put my MAC on a different ADSL box (I have 2 acccesses with 2 providers at home) and get the same issue.
    I also noticed a havy CPU load on the mDNSResponder process (at least 30%). I have restarted it, but no improvement.
    Last, I have repared the permissions.
    From those trials, it seems that the problem is on the Mac side. But I am completelly without any new idea, so I need help
    Thanks

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, or by a peripheral device. 
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including Wi-Fi on certain iMacs. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin. Test while in safe mode. Same problem? After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • IReport data retrieval from MySql database

    Hi,
    can anyone help me? i am using iReport - jasperreports to design a report using a datasource/ connections.
    i designed my report and everything works fine except that the data of the fields in mthe detail band is been retrieved more than once making the reports to have one data printed more than once(as many as possible). In my quey, i even used the "order by" as specified in the iReport manual.
    Questions: Is there to fix this so that i can have one data of a field printed only once witout repeatition in the detail band(that is, print one value then the next till the last value then stop)

    Play with the evaluated and printed when options. Another thing you should do is create a group whose evaluation string is the key from your database. every time this value changes as the records are being evaluated the detail section will be printed.

  • Data extraction from mySQL

    Dear all,
    I have to connect BI 7.0 to a mySQL database. Is there a How-To Paper?
    Is it correct, that I can NOT use DB Connect like for MSSQL?
    Do I have to go for UD Connect? I do not have any JDBC or XI experience, do I need a programmer for this or is it possible to just follow a How-To-Paper which I just havent found yet?
    Thanks in advance for any hints.
    PS: I found some posts, e.g. the following, but its still not clear to me how to go forward now. Also, there might be some enhancements with 7.0..?..
    Connecting to mySQL  - Connecting to mySQL

    You could use DB Connect to link your database.
    Check this link...
    http://help.sap.com/saphelp_nw04/helpdata/en/58/54f9c1562d104c9465dabd816f3f24/frameset.htm

  • Getting a warning everytime i connect a cable to the usb port saying it is drawing to much power from computer with it being connected to any device

    cannot connect i phone 5 or nano to usb port without warnig message appear say device is drawing to much power without a device connect to the cable

    @Steve359 Wonder if you can help???
    We have a Bretford iPad charging station (10 iPads, 30 Pin) when it's plugged into the iMac it charges and syncs all 10 iPads Just fine. We've since picked up 10 more iPads (lightening). This time we bought a Satechi 12 Port USB Hub with Power Adapter & 2 Control Switches (self powered) with wall current in an effort to save about $970 for another Bretford.
    We have tried daisy chaining the Bretford and the Hub and get the Too much power error, We have tried plugging in 10 iPads with just the hub plugged in, works fine until we plug in the Bretford, then error msg appears. (both hub and charging station plugged directly into the iMac) We tried same setup with 10 on the charging station and with the hub plugged in began adding iPad to the self powered hub and get to 13 or 14 and then we get the error. Both devices are supposed to be self powered, both plugged into the wall power, both plugged into the iMac (not Daisy chained). Both Usb cords to the Bretford and the Satechi hub are in pristine condition. The 10 iPads in the Bretford are 30 pin and the Hub are the new Lightening connections. Lightening cables are the ones supplied new with the iPads.
    iMac running 10.8
    Any idea at all how to make this work??
    signed: "Now bald because of ripping my hair out"
    Thanx
    Link to hub and specs:
    http://www.amazon.com/gp/product/B0051PGX2I/ref=oh_details_o00_s00_i00?ie=UTF8&p sc=1

  • How do i get my ipod to go from syncing with windows 7 to windows 8?

    Bought new songs and they won't sync onto my ipod when I plug it in because my new computer is Windows 8 and my old one was Windows 7. It syncs the songs from 7 but not the new ones I downloaded with windows 8

    Move all of your content from the old computer to the new computer.
    Then connect the iPhone to the new computer and sync.

  • I can no longer get video on my tv from ipad only audio when connected, any ideas"

    I used to connect my ipad 2 to my tv using a/v cable to watch YouTube, Netflix, or pretty much to watch whatever and had no issues, but now it doesn't work anymore. Only plays audio and no video.

    Make sure the plug is I secured into the iPad.

  • I recently switched to a galaxy s4 and im still getting messages on the iphone from people with imessenger I wanna stop this I just want to have the phone as an ipod now please help

    Please help

    Go to the iPhone, and go to Settings > Messages.
    Sign out of iMessage.
    You can also go to www.icloud.com and remove the iPhone from your iCloud account.
    Or, you can contact Apple support and have them assist you with removing the phone number from being associated to your Apple ID.
    Or, go to appleid.apple.com and change your primary email address and/or password to your Apple ID.

Maybe you are looking for

  • Report for serial number

    hi, For inhse material ,serial number profile is maintained.confirmation happened with serial number in MFBF(REM). i want to list out seiral numbers of material which is in storage location .any std reports is there for to display and also i want tab

  • Hiding a Particular Field in Report Builder 6.0

    Hi Folks, In one of my reports which consists of several linked tables, I want a particular field to be omitted in the report output when there are no values for a record. Even the heading/prompt for that field/column should not be printed. I tried u

  • [AwesomeWM] mouse cursor precision in java apps

    My mouse cursor isn't really precise in java apps, for example IntelliJ IDEA. The highlighted (and clicked) item is always below the cursor. In this case https://docs.google.com/file/d/0B594FZm - sp=sharing (Screenshot) the mouse cursor actually high

  • IB delivery open in MD04

    Hi All, I created a PO with 15 quantity. I did a Inbound delivery for 15 qty and Post goods receipt for the same. Then i returned 5 qty to vendor using 122 mvt type. Now in MD04 screen the inbound delivery is opened agian for 5 quantity. I found a SA

  • Maximum length of movie

    I have just barely under 2 hours of video that I have imported into iMovie. For best quality should I make this footage into 2 separate iMovie projects and burn on 2 separate DVDs (the video lends itself to being divided at the 1 hour mark), or will