我需要帮助用来自SQLContainer的数据填充Grid。我有以下代码:
public void createConnetionDB(){
try {
connectionPool = new SimpleJDBCConnectionPool(
"com.mysql.jdbc.Driver",
"jdbc:mysql://localhost:3306/test", "root", "root", 2, 5);
}
catch(Exception e){
text.setCaption(e.toString());
}
}
public SQLContainer initSQLContainer(){
TableQuery tq = null;
tq = new TableQuery("articles", connectionPool);
tq.setVersionColumn("OPTLOCK");
SQLContainer articleContainer = new SQLContainer(tq);
return articleContainer;
}
Grid articles = new Grid();
articles.setContainerDataSource(initSQLContainer());
运行它时我得到nullpointerexception。怎么了?
提前致谢
答案 0 :(得分:0)
由于变量connectionPool
为null
,您会收到异常。我想你忘了打createConnectionDB()
。
试试这样:
public SQLContainer initSQLContainer() {
createConnetionDB();
TableQuery tq = new TableQuery("articles", connectionPool);
tq.setVersionColumn("OPTLOCK");
SQLContainer articleContainer = new SQLContainer(tq);
return articleContainer;
}