[英]SQlite JDBC - ResultSet value returns NULL
I'm trying to display movie titles from the database, the problem is that if I call the rs.getString()
method it always returns null
.我正在尝试显示数据库中的电影标题,问题是如果我调用rs.getString()
方法,它总是返回null
。 The database table is properly configured with one column/two rows and connected to the java application, so I don't know where the problem is..数据库表正确配置了一列/两行,并连接到java应用程序,所以我不知道问题出在哪里..
This is my class which I call from the main function:这是我的 class,我从主 function 呼叫:
import java.sql.*;
public class Driver {
public Driver() {
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
// DriverManager.registerDriver(new org.sqlite.JDBC());
c = DriverManager.getConnection("jdbc:sqlite:test.db");
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Movies");
rs.next();
System.out.println(rs.getString("title")); // <---- prints null
stmt.close();
c.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
3 things that seem weird: 3件看起来很奇怪的事情:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.