質問

I prepared a sql script that inserts some test data into database so that you can run unit tests against it and have some unit test expectations, like there will be some properties with some values and can check validity of query by examining that data

What I need to know is how java data access layer lets you use parameters in the statements, does it allow to use named parameters which is sql server standard or it uses "?" placeholders?

So, for instance you want to execute following query

select * from items where ID = @ID

where @ID is a parameter that you can pass to the sql command before executing query.

I am sure there is something in java for that, but depending on the data provider it allows you to use named parameters or just "?" placeholders, so sql should look like

select .. from .. where ID = ?
役に立ちましたか?

解決

Normal JDBC prepared statements does not provide this functionality.

You can use NamedParameterJdbcTemplate from Spring or see the below link for the sample implementation of NamedPreparedStatement

http://www.javaworld.com/javaworld/jw-04-2007/jw-04-jdbc.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top