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

project:

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

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

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

Read More: