Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to get the contents field of a spatiallite sqlitejdbc?

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

    Default How to get the contents field of a spatiallite sqlitejdbc?

    I have this code:

    statement.executeUpdate("SELECT AddGeometryColumn('areas', 'geom', 4326, 'POLYGON', 'XY')");

    //Basic square
    //String strSt="INSERT INTO areas VALUES (1, 'zoneA', GeomFromText('POINT(1 1)',4326))";
    String strSt="INSERT INTO areas VALUES (1, 'zoneA', GeomFromText('POLYGON (0 0, 10 0, 10 10, 0 10)',4326))";

    strSt="select geom from areas where areas.label == 'zoneA'";
    ResultSet rs=statement.executeQuery(strSt);


    and it says that geom field does not exists.

    Then I:

    ResultSetMetaData rsmd = rs.getMetaData();
    int numColumns = rsmd.getColumnCount();

    // Get the column names; column indices start from 1
    for (int i=1; i<numColumns+1; i++)
    String columnName = rsmd.getColumnName(i);
    String str= rsmd.getColumnTypeName(i);
    int d= rsmd.getColumnType(i);

    columnname is 'geom'
    str is null
    d is 0
    str2 is java.lang.Object

    So how to get the value of the field?

    Thanks a lot


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Tavistock, UK
    Thanked 103 Times in 93 Posts

    Default Re: How to get the contents field of a spatiallite sqlitejdbc?

    Add code tags to your post - see the 'BB Code' link below.

    It looks like ResultSet doesn't recognise the type of the column. Try using getBytes(String) or getBinaryStream(String) to read the geom field - perhaps you may be able to construct a String from a byte array, if that works? I doubt that will work, though I'd be surprised if those two methods returned nothing. If you're using a special DB-side library, perhaps it has string-coercing functions you can use to produce a readable resultset for Java? I'm guessing at something like "SELECT STRINGIFY(geom)" - where 'STRINGIFY' is either a built-in in your DB, or provided by the spatial data library.

    I had a quick search out of curiosity and this page suggests to me that 'asText' might work:

    Last edited by Sean4u; May 26th, 2012 at 05:54 PM. Reason: added URL

Similar Threads

  1. How do I display the contents of this array?
    By mjballa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 7th, 2011, 01:17 AM
  2. frame not displaying correct contents
    By yemista in forum AWT / Java Swing
    Replies: 1
    Last Post: October 20th, 2011, 08:58 AM
  3. How to tranfer contents from Database onto the web using Java
    By abhiM in forum Java Theory & Questions
    Replies: 4
    Last Post: August 5th, 2011, 09:42 AM
  4. Replies: 3
    Last Post: April 11th, 2011, 09:51 PM
  5. Reading contents of another window
    By jimmys in forum Java Theory & Questions
    Replies: 8
    Last Post: October 4th, 2010, 11:40 PM