K
K
Kvert0072014-05-14 17:00:20
Java
Kvert007, 2014-05-14 17:00:20

Why is an error displayed when adding a record in MS SQL?

There is a piece of code. (JAVA)

sql = "SET NOCOUNT OFF INSERT INTO USER_INFO_TCC (USR_LAST_NAME,USR_FIRST_NAME,USR_MIDDLE_NAME,USR_EMAIL,USR_UDF_ADLOGIN,USR_UDF_START_DATE,USR_UDF_END_DATE,USR_UDF_JOBPOSITIONNAME,USR_UDF_PERSONNEL_NUMBER,USR_UDF_ORG_UNIT,USR_UDF_BALANCE_CODE) VALUES " +
                        "('"+USR.USR_LAST_NAME+"','"+USR.USR_FIRST_NAME+"','"+USR.USR_MIDDLE_NAME+"','"+USR.USR_EMAIL+"','"+USR.USR_UDF_ADLOGIN+"',"+USR_UDF_START_DATE_TCC+","+USR_UDF_END_DATE_TCC+",'"+USR.USR_UDF_JOBPOSITIONNAME+"','"+USR.USR_UDF_PERSONNEL_NUMBER+"','"+USR.USR_UDF_ORG_UNIT+"','"+USR.USR_UDF_BALANCE_CODE+"')";
                    System.out.println(sql);
                    TCCBDSt.executeQuery(sql);

A record is added to the table, but an exception is thrown:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
What could be the problem? SET NOCOUNT OFF has no effect.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2014-05-14
@Sumor

executeQuery is called for SELECT queries that return result sets.
In your case, you need to use executeUpdate, which is for UPDATE INSERT DELETE commands that result sets don't return.

K
Kvert007, 2014-05-15
@Kvert007

Thanks =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question