按钮-> conectaDB(连接数据库)-> inseredadosBD(将数据插入数据库)
如何将连接返回到 inseredadosBD,从方法中插入?
按钮事件:
public void inseredadosBD(String grupo, int protocolo, String dataentrada, String escrevente, String auxiliar, String datalimite) {
conectaBD();
-> here i will use the insert, i was planning to use something like conn.execute.. from here, but
}
我尝试了 conectaBD(Connection conectado);, 尝试了 conectaBD(conectado);
做类似 conectado.execute.. 之类的事情,但没有用:/
方法 conectaBD
public class metodos {
public Connection conectado;
public Connection conn;
public Connection conectaBD() {
//metodo responsavel por fazer a conexão com o BD
try {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
conn = DriverManager.getConnection("jdbc:sqlite:c:\\grupo1.db");
// Statement stm = conn.createStatement();
if (conn != null) {
System.out.println("Conectou" );
// fechaconexaoBD(conn);
} else {
System.out.println("Conexão Fail");
}
} catch (SQLException e) {
System.out.println("Erro de conexão " );
e.printStackTrace();
}
return conn;
}
..here go the rest of the code...
忘了//,我只是在尝试/测试一些东西:s