how to execute below query in java

we have written the below query in sql server and executing fine in the sql server console.i want to execute same in java through prepared statement ,spring or JPA.i put below query in some property file and want to execute it in java.


declare @temp TABLE(
  emp_id int, 
  dept_id int
)
insert into empjobs(
    emp_type
  , dept_id
   , start_date
  , status
,end_date
  
) 
output inserted.emp_id, inserted.dept_id
INTO @temp
select 'aaa',111,getdate(),'N' ,getdate()  FROM table1

select emp_id,dept_id from @temp

Open in new window

LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Make it a stored procedure or function in SQL Server and then use CallableStatement in Java to call it
0
chaitu chaituAuthor Commented:
cant we put above query in property file and calling using java prepared statement?
0
CEHJCommented:
Most probably not. Incidentally, that's not a query. It's a set of procedural statements of a proprietary kind specific to one RDBMS. That's why those statements should be a stored procedure.
0
chaitu chaituAuthor Commented:
we can do it in java usig below statements.

ps.executeUpdate(); //for insert into select statement.

ResultSet rs= ps.getGeneratedKeys();//for getting results after inserting
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chaitu chaituAuthor Commented:
no body gave an answer except me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.