我创建了一个数据库,如下所示:
Class.forName("org.sqlite.JDBC");
Connection connection = null;
try
{
connection = DriverManager.getConnection("jdbc:sqlite:ebank.db");
final Statement statement = connection.createStatement();
statement.setQueryTimeout(30);
statement.executeUpdate("create table if not exists employee (id integer,firstname string, lastname string, username string, password string, lgdin integer)");
// statement.executeUpdate("insert into person values(1, 'leo')");
// statement.executeUpdate("insert into person values(2, 'yui')");
// ResultSet rs = statement.executeQuery("select * from person");
// while(rs.next())
// {
// System.out.println("name = " + rs.getString("name"));
// System.out.println("id = " + rs.getString("id"));
// }
}
catch(SQLException e)
{
System.err.println(e.getMessage());
}
finally
{
try
{
if (connection !=null)
{
connection.close();
}
}
catch(SQLException e)
{
System.err.println();
}
}
我需要做的是从我的应用程序中的其他类访问这个数据库。首先,我试图将另一个类中的两个字符串变量添加到该数据库中,但我无法访问语句对象来执行此操作。我该怎么做?