I have a problem to insert a new quarrel of information into a list we
combined around JDBC. It throws SQLException after a ExecuteUpdate()
line.Below we yield a formula that combined a DB and a Table in this DB.
The second partial has a formula that is ostensible to insert values into
quarrel in a PatientsData table.public category DbSetUp {private
stationary Connection con;private stationary String mySqlString = "CREATE
TABLE PatientsData" + "(id INTEGER PRIMARY KEY," + "fname
VARCHAR(30) NOT NULL," + "lname VARCHAR(30) NOT NULL," +
"sex VARCHAR(1) NOT NULL," + "insurance VARCHAR(1) NOT NULL," +
"profession VARCHAR(30) NOT NULL)";//private boolean end;private
stationary String strTemp = "CREATE TABLE PatientsTemp" + "(id
INTEGER PRIMARY KEY," + "name VARCHAR(256) NOT NULL," +
"date DATE NOT NULL," + "temp NUMERIC NOT NULL)";public stationary
vacant main(String[] args) { try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); } locate
(ClassNotFoundException e) { System.out.println("Driver not
found"); e.printStackTrace(); } try { rapist =
DriverManager.getConnection("jdbc:derby:PatientDb;create=true"); }
locate (SQLException e) { System.out.println("Db not found");
e.printStackTrace(); } Statement matter = null; try{
matter = con.createStatement(); statement.execute(mySqlString);
statement.execute(strTemp); } catch(SQLException ex){
ex.printStackTrace(); }}The above formula works glorious throwing no
exceptions. we assume that both tables have been combined and a DB
exists:)Not a partial that is ostensible to insert data:public Patient
createNewPatient(int id, String fname, String lname, String sex,
String insurance, String profession) { try {
DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
} locate (SQLException e1) { System.out.println("to na
poczatku"); e1.printStackTrace(); } try{ rapist =
DriverManager.getConnection("jdbc:derby:PatientDb");
PreparedStatement ps = con.prepareStatement("INSERT INTO PatientsData
VALUES(?,?,?,?,?,?)"); System.out.println("Prepared Statement");
ps.setInt(1, id); System.out.println("set int id");
ps.setString(2, fname); ps.setString(3,lname);
ps.setString(4,sex); ps.setString(5, insurance);
ps.setString(6,profession); System.out.println("set twine
profession"); outcome = ps.executeUpdate();
System.out.println(result); relapse new
Patient(id,fname,lname,sex,insurance,profession);
//System.out.println("set twine profession"); } catch(SQLException e){
System.out.println("SQL exception"); relapse null; }}The
line: outcome = ps.executeUpdate(); throws SQLException, we have no
thought where is a mistake. we have total derby.jar into my build path.
No comments:
Post a Comment