2

EDIT: I had a letter off, it's working now.

I have the following sql statement

UPDATE names set sent_count = sent_count + 1  where user_name = 'name' AND category = 'test' AND service = 'test'

this works by increasing the sent_count each time I run the sql from PGAdmin3, but I have the following method in a Java program using Postgresql JDBC, it's not throwing any exceptions but it's not increasing sent_count here is the method below

public void increaseUsernameResponseCount(String userName, String category, String service, String country) throws SQLException
{
    Connection conn = null;
    PreparedStatement pst = null;
    // ResultSet rs = null;

    try
    {
        Class.forName("org.postgresql.Driver");
        conn = DriverManager.getConnection(url, props);
        pst = conn.prepareStatement("UPDATE names set sent_count = sent_count + 1  where user_name = ? AND category = ? AND service = ?");
        pst.setString(1, userName);
        pst.setString(2, category);
        pst.setString(3, service);

        int count = pst.executeUpdate();
        System.out.println(count);

    }
    catch (Exception e)
    {
        System.out.println(e);
    }
    finally
    {
        pst.close();
        conn.close();
    }
}

the count counter prints 0 when this method is ran. Any idea why it does not work from the method but it works when I execute the sql query?

6
  • 3
    I take it you've made absolutely sure that userName, category and service are exactly the same as in your pgadmin session? Commented Jan 4, 2013 at 11:38
  • Use System.out.println to print the values of username, category, service. Commented Jan 4, 2013 at 11:39
  • 2
    And of course make sure you're connecting to the same database, and not some UAT copy or something (been there :)) Commented Jan 4, 2013 at 11:41
  • Try use profiler to explore sql command,that sent to DB. Commented Jan 4, 2013 at 11:45
  • @ Hamlet Hakobyan - probably meant a debugger? Commented Jan 4, 2013 at 12:30

1 Answer 1

2

Check if you have two databases containing the same table. This generally happens if you work at two different locations and keep changing database names while importing it from the dump.

Also check if the "url" and "props" strings are correct for the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.