我在 id 列上加入了两个表,它们看起来像:
+-------+
| users |
+----+--+---+
| id | name |
+----+------+
+-------+
| posts |
+-------+------+---------+
| id | user_id | message |
+----+---------+---------+
现在我想选择所有帖子并包含用户名,其中:
SELECT * FROM posts, users WHERE user_id = users.id
然后我尝试通过以下方式获取值:
ResultSet rs = // SQL
if(rs.next()) {
rs.getInt("posts.id");
...
}
但是我SQLException
在执行时得到rs.getInt("posts.id")
:
java.sql.SQLException: Column 'posts.id' not found.
如何使用 JDBC 和 JavaDB/Derby 作为数据库从上面的 SQL 查询中获取值?
使用 检索值时如何区分和表id
中的列?users
posts
ResultSet