简体   繁体   中英

How to call PostgreSQL function in java?

I have PostgreSQL+PostGIS.

I java i want to call this query:

SELECT num,id,mydata, asText(the_geom) FROM filedata

But get NullPointerException .
I think its couse i try to call function asText in this query and do it wrong. What i gonna do?

UPDATE

This is my code:

IndexedContainer container = createContainer("SELECT num,id,mydata, asText(the_geom) FROM filedata");

public IndexedContainer createContainer(String SQL) throws SQLException, ClassNotFoundException
{
    Class.forName("org.postgresql.Driver");
        Connection con= null;
      con =  DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgis","postgres","123456");


    IndexedContainer container = new IndexedContainer();
    String sSQL = SQL;

    PreparedStatement ps = con.prepareStatement(sSQL);
 ////*****////
}

Most likely your problem is in the_geom - it is NOT table column (unless you did not follow any naming standards). If you are trying to build SQL in Java and pass a value from Java variable to SQL than you can use query parameters.
I suspect that you "forgot" that your SQL actually runs on SQL server where Java variables are not available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM