프로그램을 수행 중이며 삽입 명령이 올바르게 작동하고 DB (Microsoft Access)의 모든 항목이 정상인 경우에도 다음 코드는이 예외를 throw합니다. , 전혀 도움이되지 않습니다. INSERT INTO Presupuesto (Id_cliente,ID_Presuspuesto,Reserva) VALUES (1,234, false) INSERT INTO Presupuesto (Id_cliente,ID_Presuspuesto,Reserva) VALUES (1,234, false) java.sql.SQLException: General error at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source) at datos.AccesoBD.insertaPresupuesto(AccesoBD.java:137) at aplicaciones.CapaAplicacion.insertaPresupuesto(CapaAplicacion.java:81) at Interfaces.NuevoPresupuesto$2.actionPerformed(NuevoPresupuesto.java:103) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) hasta aqui bien INSERT INTO ProductoPresupuesto (Id_Producto,PrecioUd,ID_Presuspuesto,Unidades) VALUES (1,123.0,234,1); hasta aqui bien INSERT INTO ProductoPresupuesto (Id_Producto,PrecioUd,ID_Presuspuesto,Unidades) VALUES (2,270.0,234,1);
삽입이 작동하더라도 "java.sql.SQLException : 일반 오류"
인쇄 된 문장은 인쇄 된 값이 DB에 저장됩니다. 나는 DB를 확인했고 모든 이드도 거기에있다.
ProductoPresupuesto는 기본 키로 두 개의 외래 키를 가지고 있으며 결코 반복되지 않습니다 (동시에 두 개를 모두 의미합니다).
다음은 내 코드를 볼 수 있습니다 : 이미 존재 "Producto"에서
public void insertaPresupuesto(Presupuesto presu){
String insert;
for(int i=0; i<presu.getL().size(); i++){
insert="INSERT INTO Presupuesto (Id_cliente,ID_Presuspuesto,Reserva) VALUES ("+presu.getC().getID_Cliente()+","+presu.getId()+", "+presu.isReserva()+")";
Statement stm1;
try {
stm1 = conn.createStatement();
System.out.printf("%s\n",insert);
stm1.executeUpdate(insert);//THIS IS THE LINE 137
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(int i=0; i<presu.getL().size(); i++){
float precio=presu.getL().get(i).getPrecioProd()-presu.getL().get(i).getRebaja();
System.out.printf("hasta aqui bien\n");
insert="INSERT INTO ProductoPresupuesto (Id_Producto,PrecioUd,ID_Presuspuesto,Unidades) VALUES ("+presu.getL().get(i).getId()+","+precio+","+presu.getId()+","+presu.getUnidades().get(i)+");";
Statement stm2;
try {
stm2 = conn.createStatement();
System.out.printf("%s\n",insert);
stm2.executeUpdate(insert);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
모든 항목을 클라이언트도 존재한다. 이 함수는 Presupuesto (예외없이 성공)에 삽입 한 다음 ProductoPresupuesto에 삽입하려고 시도합니다.
기존 테이블은 Cliente (예를 들어), Producto (이미로드 된 제품 포함), Presupuesto (예외가 발생하지 않음) 및이 마지막 두 테이블 사이에있는 테이블입니다. ProductoPresupuesto inserts하지만 Object Presupuesto (presu)에 둘 이상의 Producto가있는 경우에만이 예외가 throw됩니다.
거의 일주일 동안 시도했기 때문에 아이디어를 줄 수 있기를 바랍니다 (PreparedStatements도 마찬가지 임).)
stm1.executeUpdate (insert); 죄송합니다. 코드 내부를 강조 표시하는 옵션을 찾지 못했습니다. @SUNNYben – Chupitel