java - Named parameters in JDBC -
are there named parameters in jdbc instead of positional ones, @name
, @city
in ado.net query below?
select * customers name=@name , city = @city
jdbc not support named parameters. unless bound using plain jdbc (which causes pain, let me tell that) suggest use springs excellent jdbctemplate can used without whole ioc container.
namedparameterjdbctemplate supports named parameters, can use them that:
namedparameterjdbctemplate jdbctemplate = new namedparameterjdbctemplate(datasource); mapsqlparametersource paramsource = new mapsqlparametersource(); paramsource.addvalue("name", name); paramsource.addvalue("city", city); jdbctemplate.queryforrowset("select * customers name = :name , city = :city", paramsource);
Comments
Post a Comment