자바의 SQL 삽입을 수행하려고하지만, 불가능 HSQLDB에 커밋 커밋 :자바는 HSQLDB
public class VehiculeDAO extends DAO<Vehicule> {
public Vehicule create(int marque, int moteur, int prix, String nom) {
System.out.println("\t marque:" + marque +"moteur:"+moteur+"prix:"+prix+"nom:"+nom);
Vehicule vehicule = new Vehicule();
String query = " INSERT INTO VEHICULE (MARQUE, MOTEUR, PRIX, NOM) VALUES (0,4,100,'test2');";
query += "commit;";
try {
connect.setAutoCommit(true);
ResultSet result = this.connect.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE).executeQuery(" INSERT INTO VEHICULE (MARQUE, MOTEUR, PRIX, NOM) VALUES (0,4,100,'test3')");
connect.commit();
result.close();
} catch (SQLException e) {
e.printStackTrace();
}
//return;
return vehicule;
}
삽입이 완료 되었으나 확정되지 않습니다. 디버깅에 대한 아이디어가 있으십니까?
어플리케이션의 간략한 설명 요청한 같이
HsqldbConnection
:
public class HsqldbConnection {
private HsqldbConnection() {
try {
connect = DriverManager.getConnection(url, user, passwd);
} catch (SQLException e) {
e.printStackTrace();
}
}
// ...
TestDAO
:
public class TestDAO {
public static void main(String[] args) throws SQLException {
DAO<Vehicule> vehiculedao = DAOFactory.getVehiculeDAO();
Vehicule vehicule = vehiculedao.create(0 ,5, 100, "test");
// ...
DAOFactory
:
public class DAOFactory {
protected static final Connection conn = HsqldbConnection.getInstance();
public static DAO getMarqueDAO(){
return new MarqueDAO(conn);
}
public static DAO getVehiculeAO(){
return new MarqueDAO(conn);
}
}
커밋 명령을 VehiculeDAO
클래스에 삽입해야합니다.
Test commit
: 공공 정적 무효 메인 (문자열 []에 args) { 시도 {
String url = "jdbc:hsqldb:file:hsqldb/database/VEHICULE";
String user = "";
String passwd = "";
Connection conn = DriverManager.getConnection(url, user, passwd);
Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
PreparedStatement prepare = conn.prepareStatement("INSERT INTO VEHICULE (MARQUE, MOTEUR, PRIX, NOM) VALUES (0,4,100,'testcommit')");
prepare.executeUpdate();
conn.commit();
prepare.close();
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
자동 커밋을 true로 설정하면 해당 상황에서 'Connection.commit()'을 호출하면 오류가 발생합니다. 이는 드라이버가 명령문 실행 후 자동으로 커밋되기 때문입니다. 너의 문제는 아마도 다른 곳에있을 것이다. 실제로 문제를 나타내는 [mcve]를 만드십시오. –
는 동의하지만, 찾을 수없는 곳이다 문제, 패키지 –
개인 HsqldbConnection() { \t \t 시도 { \t \t \t 연결 = DriverManager.getConnection를 (URL, 사용자, passwd를) 최소한의 프리젠 테이션 이하; \t \t} catch (SQLException e) { \t \t \t e.printStackTrace(); \t \t \t}} –