Results 1 to 7 of 7
  1. #1
    ciglesias is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default Problem inserting String into postgresql.

    Hello,

    I'm trying to execute an insert into an postgresql database from java.

    This is the code:

    .
    .
    String queryPostgresql = "select merge_db("+ oid +", "+ uid +", to_timestamp("+ etime +"), to_timestamp("+ pstime +"), to_timestamp("+ rstime +"), "+ elapsed +", "+ espera +", "+ numcpu +", "+ numcpu +", "+ memory +", "+ error +", "+ etiqueta +", "+ finalizado +")";
    .
    .

    select_merge is a function in the postgresql database.
    Everything is working but the field "etiqueta" wich is a String. When i try to insert it there's an error:

    error: the column xxx does not exist.

    where xxx is the String I typed in.

    Is there something I can do?

    If something is not understandable please ask.

    Thanks.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    See the JDBC tutorials for JDBC PreparedStatement.

  3. #3
    ciglesias is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    I can't use prepared statement:

    Can't use query methods that take a query string on a PreparedStatement.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Yes you can, if you set it up intelligently enought, and that above is still easier done with a PreparedStatement.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    In nay case, if you are getting "column does not exist" then it's pretty that that column doesn't exist in that table. You either typed it wrong or it simply doesn't exist as a reserved word would result in an "invalid column name" or something like error, not the error you got.

  6. #6
    ciglesias is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Hi, thanks for the heads up.

    The problem with the "column does not exist" was that the function in postgresql needed the string to be between ' ', i solved it by surrounding the string with those (not ideal, but for now working).

    I'm getting now an "A result was returned by the statement, when none was expected." from the postgresql driver (i'm working on it), but the data and the function are working fine.

    Thanks.

    Edit, nevermind, i was using a executeUpdate but with executeQuery it works just fine.
    Last edited by ciglesias; 04-13-2011 at 05:47 PM.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by ciglesias View Post
    Hi, thanks for the heads up.

    The problem with the "column does not exist" was that the function in postgresql needed the string to be between ' ', i solved it by surrounding the string with those (not ideal, but for now working).
    And a preparedstatement would have made that a moot point, BTW.

Similar Threads

  1. Replies: 5
    Last Post: 03-29-2011, 01:16 PM
  2. Problem when inserting in java
    By aleksandar in forum Java Applets
    Replies: 2
    Last Post: 02-08-2011, 02:21 PM
  3. Problem inserting into database
    By Unnel in forum JDBC
    Replies: 13
    Last Post: 01-23-2011, 10:23 PM
  4. problem with inserting new record
    By gerard kowara in forum JDBC
    Replies: 1
    Last Post: 10-26-2010, 12:33 PM
  5. Replies: 0
    Last Post: 02-07-2008, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •