|
@@ -0,0 +1,52 @@
|
|
|
+package com.lovecoding.jdbc;
|
|
|
+
|
|
|
+import com.alibaba.druid.pool.DruidDataSource;
|
|
|
+import com.lovecoding.jdbc.dao.Test;
|
|
|
+import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class Application {
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ ClassPathXmlApplicationContext context =
|
|
|
+ new ClassPathXmlApplicationContext("jdbc.xml");
|
|
|
+ JdbcTemplate template = context.getBean("jdbcTemplate", JdbcTemplate.class);
|
|
|
+
|
|
|
+ //获取数据库单独字段
|
|
|
+// Integer integer = template.queryForObject(
|
|
|
+// "SELECT count(*) AS c FROM test",
|
|
|
+// Integer.class
|
|
|
+// );
|
|
|
+ //新增操作
|
|
|
+// int update = template.update(
|
|
|
+// "INSERT into test values (?), (?)",
|
|
|
+// 5, 6
|
|
|
+// );
|
|
|
+ //更新操作
|
|
|
+// int update = template.update(
|
|
|
+// "UPDATE test set id = ? where id = ?",
|
|
|
+// 100, 1
|
|
|
+// );
|
|
|
+ //删除操作
|
|
|
+// int update = template.update(
|
|
|
+// "DELETE from test where id = ?",
|
|
|
+// 100
|
|
|
+// );
|
|
|
+ //查询数据实体
|
|
|
+// Test test = template.queryForObject(
|
|
|
+// "SELECT * FROM test LIMIT 1",
|
|
|
+// new BeanPropertyRowMapper<>(Test.class));
|
|
|
+
|
|
|
+ //查询一个数据列表
|
|
|
+// List<Test> query = template.query(
|
|
|
+// "SELECT * FROM test",
|
|
|
+// new BeanPropertyRowMapper<>(Test.class)
|
|
|
+// );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|