spring mysql_eclipse中spring访问mysql的简易实现-阿里云开发者社区
eclipse中构建一个maven基础上的带有TestNG测试插件的spring项目
目录结构如下所示:
这个简易的实现,包括四个文件
1.java源码(访问数据库代码)
2.测试源码(TestNG测试插件的代码)
3.spring配置文件(让spring起作用)
4.pom配置文件(基于maven构建项目)
下面罗列一下四个文件的代码:
1.java源码
package com.infotech.access.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import com.infotech.access.domain.CheckedList;
@Repository
public class CheckedlistDao {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
/**
* @param skostl
* @return
*/
public String getData(String smname) {
final String sr =null;
jdbcTemplate.query("select * from ruku_log where SN =?", new Object[] { smname }, new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
String sr2 = rs.getString("logcode");
}
});
return sr;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
2.测试源码
package com.infotech.access.dao;
import java.util.Date;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import com.infotech.access.domain.CheckedList;
import static org.testng.Assert.*;
@ContextConfiguration("classpath*:/ruku-context.xml")
public class CheckedlistDaoTest extends AbstractTransactionalTestNGSpringContextTests{
private CheckedlistDao cld;
@Autowired
public void setCheckedlistDao(CheckedlistDao cldlocal){
this.cld = cldlocal;
}
@Test
public void testAcess() {
String sb1 = this.cld.getData("1");
System.out.println(sb1);
}
}
3.spring配置文件
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
classpath:/org/springframework/beans/factory/xml/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
classpath:/org/springframework/context/config/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
destroy-method="close"
p:driverClassName="com.mysql.cj.jdbc.Driver"
p:url="jdbc:mysql://localhost:6062/ruku_v1?serverTimezone=GMT"
p:username="root"
p:password="password" />
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dsmysql" />
p:dataSource-ref="dsmysql" />
4.maven配置文件
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
infotech.com
ruku
war
0.0.1-SNAPSHOT
ruku Maven Webapp
http://maven.apache.org
junit
junit
4.12
org.springframework
spring-context
4.3.11.RELEASE
net.sf.ucanaccess
ucanaccess
4.0.1
org.springframework
spring-jdbc
4.3.11.RELEASE
mysql
mysql-connector-java
8.0.7-dmr
org.testng
testng
6.8
test
org.springframework
spring-test
4.3.11.RELEASE
test
org.springframework
spring-core
4.3.11.RELEASE
commons-dbcp
commons-dbcp
1.4
org.springframework
spring-beans
4.3.11.RELEASE
ruku
上述几个文件的逻辑关系如下图:
上述spring配置文件中负责数据库连接的部分,url中使用的localhost而不是ip地址。如果你全新安装了mysql那么默认情况下是无法使用ip地址进行远程访问或者甚至本地访问的。
需要给mysql开通远程访问的权限。
spring mysql_eclipse中spring访问mysql的简易实现-阿里云开发者社区相关推荐
- mysql double 存储_关于MYSQL中FLOAT和DOUBLE类型的存储-阿里云开发者社区
关于MYSQL中FLOAT和DOUBLE类型的存储 重庆八怪 2016-04-12 844浏览量 简介: 关于MYSQL中FLOAT和DOUBLE类型的存储 其实在单精度和双精度浮点类型存储中其存储方 ...
- 不属于python标准库的是_《Python Cookbook(第2版)中文版》——1.10 过滤字符串中不属于指定集合的字符-阿里云开发者社区...
本节书摘来自异步社区<Python Cookbook(第2版)中文版>一书中的第1章,第1.10节,作者[美]Alex Martelli , Anna Martelli Ravenscro ...
- mysql5.5索引如何定义_MySQL5.5索引数在InnoDB引擎内与索引数在mysql中定义的数量是不一致问题-阿里云开发者社区...
在查看MySQL错误日志的时候发现这样的错误,如下: 160322 21:42:59 [ERROR] Table baby/baby_order contains 12 indexes inside ...
- 查询mysql数据库表占用空间大小_查看 MySQL 数据库中每个表占用的空间大小-阿里云开发者社区...
如果想知道MySQL数据库中每个表占用的空间.表记录的行数的话,可以打开MySQL的 information_schema 数据库.在该库中有一个 TABLES 表,这个表主要字段分别是: TABLE ...
- 阿里云mysql 日志_mysql日志-阿里云开发者社区
mysql日志 mysql有以下几种日志: 错误日志: log-error 查询日志: log 慢查询日志: log-slow-queries 更新日志: log-update 二进制日志: log- ...
- mysql error 1594_【MySQL】解决mysql的 1594 错误-阿里云开发者社区
对于主从架构的mysql,当发生主机断电或者其他原因异常crash的时候, slave的容易发生读取binlog出错的问题,最常见的是 show slave status \G; Master_Log ...
- mouted vue 操作dom_vue中使用refs定位dom的坑-阿里云开发者社区
使用element-ui的表单验证,出现"this.$refs.ruleForm.validate is not a function" 使用mint-ui的popup,在moun ...
- vue怎么vw布局好用_Vue项目中使用vw实现移动端适配-阿里云开发者社区
我们在vue移动端项目中的适配一般都采用rem,但是rem也不是能兼容所有的终端. 随着viewport单位越来越受到众多浏览器的支持,下面将简单介绍怎么实现vw的兼容问题,用vw代替rem 当我们采 ...
- python集合可以修改吗_修改包含Python3中的集合的集合列表-问答-阿里云开发者社区-阿里云...
我试图创建一个以元组为元素的列表.每个元组都有4个整数.前两个整数是对2个range进行压缩的结果,而其他2个则是对2个不同的整数进行压缩的结果. 我正在使用此代码创建元组和最终列表,这些列表是从笛卡 ...
最新文章
- 洛阳综合保税区正式获国务院批复同意设立
- Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(八)
- 由通知栏进入到应用的尝试
- R语言爬虫系列(1)XML抓取表格数据
- vue遇到ie兼容问题如何处理_静电喷涂设备遇到紧急事故应该如何处理
- apache安装、配置虚拟主机、配置日志
- k3 梅林固件设置_OpenWrt中,旁路由的设置与使用
- 还原数据库SQL语句
- 维生素D与肠道菌群的互作
- 关闭windows defender安全中心的方法
- 如何连接别人电脑/如何看自己电脑IP地址+ping命令+DOS窗口
- 第一届中兴捧月算法大赛迪杰斯特拉派解决方案
- 推荐 - 将多种格式的 Office 文件转换为 PPT 和图片
- 汽车功能安全标准ISO 26262导入实践(下)
- ac2 hap mikrotik_MikroTik 2018第一款新品hAP ac2
- JAVA毕业设计Web端校园报修系统计算机源码+lw文档+系统+调试部署+数据库
- ext2 grid 封装 (包含增删改查 导入导出等操作)
- HTML5期末大作业:动漫网页主题设计——卡通漫画教育首页HTML+CSS+JavaScript 动漫网页HTML代码 学生网页课程设计期末作业下载 动漫大学生网页设计制作成...
- 射影几何 -- 空间射影几何 1
- c# 火狐浏览器怎么嵌入窗体中_正在学c# winform,问各位前辈一下 能调用火狐或者其他的浏览器吗?...