How do you select from multiple tables in sqlite in Java?

后端 未结 2 1581
萌比男神i
萌比男神i 2021-01-28 21:58

I\'m trying to learn how to use an sqlite database in a java program. (not Android). I went to this link, download the jdbc library and copied the example. The example worked wi

2条回答
  •  粉色の甜心
    2021-01-28 22:25

    The SQLite documentation says:

    The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.

    You should either use the column name that SQLite happens to use:

    rs.getString("name")
    

    or give the result column a unique name:

    executeQuery("select person.name AS person_name, ...")
    rs.getString("person_name")
    

    or just use the column index:

    rs.getString(1)
    

提交回复
热议问题