Hello, members of the forum.

The problem with the UPDATE request was brought to me by you. It consists in the following. Program at request execution

String sqlReqest = "UPDATE "+strTableName+" SET Question='"+strQestoinText+"',FirstAnswer='"+strFirstAnswer+"',SecondAnswer='"+strSecondAnswer+"',ThirdAnswer='"+strThirdAnswer+"',FourAnswer='"+strFourthAnswer+"',TrueResolt='0110' WHERE Question='"+strRedactRecoedQestion+"'"; System.out.println(sqlReqest); 

returns me an error:

java.sql.SQLException: [Microsoft][Драйвер ODBC dBase] Слишком мало параметров. Требуется 3.

The request in the console looks like this:

 UPDATE TST7.DBF SET Question='hhh234g4t56gferthgdfd',FirstAnswer='ghfbvdsfgb',SecondAnswer='hbgvfdsfgbhnvf',ThirdAnswer='sdf ghjngbvfc',FourAnswer='dgfbhnjmkujhygtf',TrueResolt='0110' WHERE Question='234g4t56gferthgdfd' 

Another interesting point is that this very query of the form

 "UPDATE" + strTableName + "SET Question = '" + strQestoinText + "' where Question = '" + strOldQuestion + "' 

it is executed without problems, but only I change the number of fields in WHERE or after it, the same error is obtained ((

Tell me, please, where I screwed up, where could be the error?

  • the request in the console fulfills? - Gorets
  • You mean I ran the query through the console-no - pj-infest
  • statement = connection.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); instead of statement = connection.createStatement (); big weather does not? - pj-infest
  • I already wrote in your past question - check the table and the field in it .. maybe these are fields in different tables, maybe a typo in the column name - Gorets
  • I perform the query to the newly created table, the name of the fields in the update request was copied from the table creation request - pj-infest

2 answers 2

This is of course most likely a student lab, but NEVER write such horror even at home! There is a wonderful PreparedStatement in which you can do this:

 PreparedStatement ps = conn.prepareStatement("update table set question = ?, FirstAnswer = ? where question = ?"); ps.setString(1, "first"); ps.setString(2, "second"); ps.setString(3, "third"); ps.execute(); 

The meaning of PreparedStatement is to delimit the request parameters from the request itself. For example, enter in your example a string with a single quote, the result will not keep you waiting.

  • Good for you, brother ... I never had a hand to write the answer to such a clumsy question - Barmaley

I found a problem, it concludes that the request to create a table gave the names of the columns

Question

FirstAnswer

Secondnswer

ThirdAnswer

FourAnswer

Trueresolt

when creating the table, the field names were truncated to 10 characters and it turned out

Question

Firstanswewe

SecondAnsw

ThirdAnswe

FourAnswer

Trueresolt

updating such cropped fields works correctly, thanks for the help