First, using the Org.springframework.jdbc.datasource.DriverManagerDataSource class to achieve
The 1.applicationcontext.xml configuration is as follows:
<BeanID= "DataSource"class= "Org.springframework.jdbc.datasource.DriverManagerDataSource"> < Propertyname= "Driverclassname"value= "Com.mysql.jdbc.Driver"/> < Propertyname= "username"value= "root"/> < Propertyname= "Password"value= "Zdsoft"/> < Propertyname= "url"value= "jdbc:mysql://172.23.88.107:3306/test?useunicode=true&characterencoding=utf-8& SERVERTIMEZONE=UTC "/></Bean> <BeanID= "JdbcTemplate"class= "Org.springframework.jdbc.core.JdbcTemplate"> < Propertyname= "DataSource"ref= "DataSource"/></Bean>
The code for 2.Java is as follows:
Public Static voidMain (string[] args) {Abstractapplicationcontext ctx=NewClasspathxmlapplicationcontext ("Applicationcontext.xml"); JdbcTemplate JdbcTemplate= (JdbcTemplate) ctx.getbean ("JdbcTemplate"); String SQL= "SELECT * FROM Stat_app"; Jdbctemplate.query (SQL,NewRowCallbackHandler () {@Override Public voidProcessrow (ResultSet RSet)throwsSQLException {System.out.println (rset.getstring ("Source_market") + "\ T" + rset.getstring ("Violations_type"))); } });}
Description
The ①mysql URL configuration requires attention to the encoding and time zone, otherwise there will be an error. At the same time, the & symbol must be escaped using &.
② query data into the Processrow, each row of data will be called once this method.
Second, using the Org.apache.commons.dbcp.BasicDataSource class to achieve
Java Spring JDBC Proxy access