Simple use of namedparameterjdbctemplate of spring

Spring JDBC package provides a JdbcTemplate and its two brothers SimpleJdbcTemplate and NamedParameterJdbcTemplate.

NamedParameterJdbcTemplate class is based on the JdbcTemplate class, and it is encapsulated to support named parameter feature.

NamedParameterJdbcTemplate mainly provides the following three methods: the execute method, method of query and queryForXXX, update and batchUpdate method.

Example in the


String username = “root”;
String password = “root”;
String driver = “com.mysql.jdbc.driver”;
String url = “JDBC: mysql:// = utf-8 “;

	Connection conn= DriverManager.getConnection(url, username, password);

	DataSource dataSource=new SingleConnectionDataSource(conn,false);
	NamedParameterJdbcTemplate jdbc=new NamedParameterJdbcTemplate(dataSource);
	List list = jdbc.queryForList("select * from fw_dir",new HashMap<>());

Read More: