Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.5K
Views
tiene un error en su sintaxis SQL; consulte el manual que corresponde a la versión de su servidor MariaDB para conocer la sintaxis correcta para usar cerca de ' ' en la línea 1

Intenté insertar los siguientes datos en la base de datos. pero me da lo anterior este error. tiene un error en su sintaxis SQL; Consulte el manual que corresponde a la versión de su servidor MariaDB para conocer la sintaxis correcta para usar cerca de ' ' en la Línea 1.

Intenté varias cosas pero no se soluciona.

 try{ Statement stat = Database.getStatement(); stat.executeUpdate("INSERT INTO"+" admission"+ " (a_id,sickness,recPhysicianDetails, admittedDate,Patient_ID,Doctor_id,Doctor_id1)"+" VALUES ('"+txt1.getText()+"', '"+txt7.getText()+"','"+txt8.getText()+"', '"+txt6.getText()+"', ( SELECT ID FROM patient WHERE Patient_name='"+txt3.getText()+"' ), ( SELECT ID FROM employee WHERE Name='"+txt9.getText()+"' ), ( SELECT ID FROM employee WHERE Name='"+txt10.getText()+"')" ); } catch(Exception e){ e.printStackTrace(); }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

En su solución, las comillas ( ' ) no están colocadas correctamente, además falta un corchete de cierre al final. El uso de PreparedStatement se asegurará de que no tenga que preocuparse por las comillas, intente esto:

 Connection conn = //get connection PreparedStatement stat = conn.prepareStatement("INSERT INTO admission (a_id,sickness,recPhysicianDetails,admittedDate,Patient_ID,Doctor_id,Doctor_id1)" +" VALUES(?, ?, ?, ?, (SELECT ID FROM patient WHERE Patient_name = ?),(SELECT ID FROM employee WHERE Name = ?),(SELECT ID FROM employee WHERE Name = ?))"); stat.setString(1, txt1.getText()); stat.setString(2, txt7.getText()); stat.setString(3, txt8.getText()); stat.setString(4, txt6.getText()); stat.setString(5, txt3.getText()); stat.setString(6, txt9.getText()); stat.setString(7, txt10.getText()); stat.executeUpdate();
over 4 years ago · Santiago Trujillo Report

0

Sugeriré usar una declaración preparada en lugar de llamar directamente al valor desde el cuadro de texto.

 try{ Statement stat = Database.getStatement(); stat.executeUpdate("INSERT INTO admission"+ "(a_id,sickness,recPhysicianDetails,admittedDate,Patient_ID,Doctor_id,Doctor_id1)"+ " VALUES('"+txt1.getText()+"','"+txt7.getText()+"','"+txt8.getText()+"','"+txt6.getText()+"',"+ "(SELECT ID FROM patient WHERE Patient_name='"+txt3.getText()+"'),"+ "(SELECT ID FROM employee WHERE Name='"+txt9.getText()+"'),"+ "(SELECT ID FROM employee WHERE Name='"+txt10.getText()+"')"); } catch(Exception e){ e.printStackTrace(); }

Aquí insertó algunas comillas dobles en lugares incorrectos, verifíquelo, debería funcionar.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!