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

后端 未结 2 1582
萌比男神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)
    
    0 讨论(0)
  • 2021-01-28 22:48

    You should define alias for table name as below

    select pc.name, ps.name from purchase as pc inner join person as ps on ps.id = pc.id
    
    0 讨论(0)
提交回复
热议问题