社区
Java SE
帖子详情
Spring jdbcTemplate
cpliu903
2009-07-27 03:44:52
Spring jdbcTemplate
org.springframework.jdbc.core.JdbcTemplate
怎样可以取的 table column name?
可否给例子?
...全文
106
2
打赏
收藏
Spring jdbcTemplate
Spring jdbcTemplate org.springframework.jdbc.core.JdbcTemplate 怎样可以取的 table column name? 可否给例子?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
网站推广优化yetaoaiueo
2009-07-27
打赏
举报
回复
import javax.sql.DataSource;
import java.sql.*;
import org.springframework.jdbc.core.JdbcTemplate;
public class UserDAO {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public void insertUser(User user) {
Connection conn = null;
Statement stmt = null;
try {
conn = dataSource.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO USER VALUES('"+ user.getId() + "', '"
+ user.getName() + "', '"
+ user.getSex() + "', '"
+ user.getAge() + "')");
}
catch(SQLException e) {
e.printStackTrace();
}
finally {
if(stmt != null) {
try {
stmt.close();
}
catch(SQLException e) {
e.printStackTrace();
}
}
if(conn != null) {
try {
conn.close();
}
catch(SQLException e) {
e.printStackTrace();
}
}
}
}
}
2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/TestDB</value>
</property>
<property name="username">
<value>caterpillar</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="userDAO" class="onlyfun.caterpillar.UserDAO">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate"/>
</property>
</bean>
</beans>
forandever
2009-07-27
打赏
举报
回复
用这个就是使用的原生SQL 查询了
那么获取table Name,table comment,column Name, column comment等等信息,主要是依赖于你的SQL语句去数据库中查询。SQL语句有了之后,由JdbcTemplate 去执行查询,然后根据获取结果去进行你需要的操作。
对应不同的数据库,需要的查询语句是不一样的,
给你个查询的MySQL例子,其他的你自己去查吧:
查询 columns :
select * from information_schema.columns where table_schema = ? and table_name = ?
查询 tables :
select * from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = ? and TABLE_TYPE = 'BASE TABLE'
Spring
——
JdbcTemplate
一、概述 二、对象创建 2.1 需要导入的 jar 包 2.2 创建
JdbcTemplate
对象 2.3 配置
Spring
内置数据源 一、概述
JdbcTemplate
是
Spring
框架中提供的一个对象,是对原始 Jdbc API 对象的简单封装。
Spring
框架为我们提供了很多 的操作模板类。 对象创建 2.1 需要导入的 jar 包 <dependencies&...
Spring
boot
jdbcTemplate
文章目录上一节
Spring
boot lombok源码下一节
Spring
boot 数据库连接池
Spring
boot
jdbcTemplate
上一节
Spring
boot lombok
Spring
boot lombok 源码
spring
boot学习指南 下一节
Spring
boot 数据库连接池
Spring
boot 数据库连接池
Spring
boot
jdbcTemplate
...
Spring
JdbcTemplate
基本使用
Spring
JdbcTemplate
基本使用 文章目录
Spring
JdbcTemplate
基本使用1.
JdbcTemplate
概述2.
JdbcTemplate
开发步骤3.快速入门4.
Spring
产生
JdbcTemplate
对象 1.
JdbcTemplate
概述 它是
spring
框架中提供的一个对象,是对原始繁琐的Jdbc API对象的简单封装。
spring
框架为我们提供了很多的操作模板类。例如:操作关系型数据的
JdbcTemplate
和HibernateTemplate,操作nosql数据库的Red
Spring
——
JdbcTemplate
JdbcTemplate
1、
JdbcTemplate
(概念和准备) 1.1、什么是
JdbcTemplate
?
Spring
框架对 JDBC 进行封装,使用
JdbcTemplate
方便实现对数据库操作。 1.2、准备工作 (1)引入相关 jar 包 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dsl09qA6-1639402734125)(素材/所需要的依赖.png)] (2)在
spring
配置文件配置数据库连接池 <!-- 数据库连接池 --> &
Spring
框架|集成
JdbcTemplate
文章目录(1)编写
Spring
配置文件(2)配置数据源(3)配置
JdbcTemplate
模板对象(4)测试
Spring
框架集成
JdbcTemplate
关于
Spring
的
JdbcTemplate
介绍 完整的XML配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.
spring
framework.o...
Java SE
62,621
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章