私は次のようにデータベースを作成しました:
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();
}
}
私がする必要があるのは、私のアプリケーションの他のクラスからこのデータベースにアクセスできることです。まず、別のクラスからこのデータベースに2つの文字列変数を追加しようとしていますが、ステートメントオブジェクトにアクセスしてこれを行うことができません。どうすればいいですか?