I'm salvaging Java code left for me from the previous employee, I was only left with the source code itself, I've had to recreate DB structure by myself. So far I fully restored it, but one line always throws exceptions at me and I can't understand why.
connBeztirazh.execSQLU("declare @ki table (ID_ki int); " +
"declare @bil table (ID_bilet int); " +
"insert into ki (i1,i2,i3,i4,i5,i6) output inserted.ID_ki into @ki values ("+i1+","+i2+","+i3+","+i4+","+i5+","+i6+"); " +
"insert into bilet(ID_ki,data) output inserted.ID_bilet into @bil values ((select ID_ki from @ki),(select SYSDATETIME())); " +
"insert into rezultat (ID_players, ID_bilet) output inserted.ID_bilet values ((select ID_players from players where telnomer='"+number+"'),(select ID_bilet from @bil));", false);
This line throws out the following exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'ki'.
I triple-checked everything, I recreated tables bilet
, players
and rezultat
, they are used elsewhere in the code and everything's alright. As far as I understand SQL, ki and bil are temporary tables and since they are created and accessed in the same query there could not be any access/session problems.
In this case, I overlooked that in fact there are two tables: constant table ki
and variable table ki
. They are referenced by ki
and @ki
respectively, which is a really bad way to name your tables. After adding table ki
to the database, everything started working as intended, as far as I can tell.
Thanks to everyone who commented on the post.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.