异常 SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS

异常 SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS

最近在学习JAVAEE数据库开发过程中出现了一些小错误,今天来分享下我的解决办法

首先是异常SQLErrorcodes的错误,意思其实是数据库字段与输入字段不匹配,这么一讲的话稍微具备一点专业知识好好检查自己的代码便可以解决,
还有个小小小细节,可能你没有加@Test = =。。。我就是- -,
呐,贴上代码你们看。我是个笨比笨比,你们不许嘲笑我!!

package chapter04;
import java.util.List;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
public class JdbcTemplateTest {
	/**
	 * 使用execute()方法建表
	 */
	public static void main(String[] args) {
		// 加载配置文件
		ApplicationContext applicationContext = 
		   new ClassPathXmlApplicationContext("applicationContext.xml");
		// 获取JdbcTemplate实例
		JdbcTemplate jdTemplate = 
			   (JdbcTemplate) applicationContext.getBean("jdbcTemplate");
		// 使用execute()方法执行SQL语句,创建用户账户管理表account
		jdTemplate.execute("create table account(" + 
					         "id int primary key auto_increment," +
					         "username varchar(50)," + 
					         "balance double)");
		System.out.println("账户表account创建成功!");
	}
//	@Test
//	public void mainTest() {
//	    // 加载配置文件
//	    ApplicationContext applicationContext = 
//	            new ClassPathXmlApplicationContext("applicationContext.xml");
//	    // 获取JdbcTemplate实例
//	    JdbcTemplate jdTemplate = 
//	            (JdbcTemplate) applicationContext.getBean("jdbcTemplate");
//	    // 使用execute()方法执行SQL语句,创建用户账户管理表account
//	    jdTemplate.execute("create table account(" + 
//	                           "id int primary key auto_increment," +
//	                           "username varchar(50)," + 
//	                           "balance double)");
//	    System.out.println("账户表account创建成功!");
//	}
	@Test
	public void addAccountTest() {
		 ApplicationContext applicationContext=new
	                ClassPathXmlApplicationContext("applicationContext.xml");
	        //2.获取AccountDao实例,在Bean中调用了AccountDaoImpl方法
	        AccountDao accountDao=(AccountDao)applicationContext.getBean("accountDao");
	        //3.创建Account对象,并向Account对象中添加数据
	        Account account=new Account();
	        account.setUsername("tom");
	        account.setBalance(100.00);
	        //执行addAccount()方法,并获取返回结果
	        int num=accountDao.addAccount(account);
	        if (num>0)
	        {
	            System.out.println("成功修改了"+num+"条数据!");
	        }else
	        {
	            System.out.println("插入操作执行失败!");
	        }
	}
	
}

但是,今天我在调试的过程中,发现还有一种情况,还没有找到答案,看看大佬们能帮我找找错嘛。

	@Test
	public void findAllAccountTest() {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		AccountDao accountDao = (AccountDao)applicationContext.getBean("accountDao");
		
		//执行findAllAccountTest方法,查询所有的账号,并获取返回结果
		List<Account> account=accountDao.findAllAccount();
		for(Account act : account) {
			System.out.println(act);
		}
	}

这个是查找表中全部数据,还有配置文件我也发出来

	<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-4.3.xsd	“>
  <!-- 1配置数据源 -->
	<bean id="dataSource" class=
     "org.springframework.jdbc.datasource.DriverManagerDataSource">
		<!--数据库驱动 -->
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<!--连接数据库的url -->
		<property name="url" value="jdbc:mysql://localhost:3306/spring" />
		<!--连接数据库的用户名 -->
		<property name="username" value="root" />
		<!--连接数据库的密码 -->
		<property name="password" value="1041642517" />
	</bean>
	<!-- 2配置JDBC模板 -->
	<bean id="jdbcTemplate" 
		   class="org.springframework.jdbc.core.JdbcTemplate">
		<!-- 默认必须使用数据源 -->
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<!--定义id为accountDao的Bean-->
<bean  id="accountDao" class="chapter05.AccountDaoImpl">
		<!-- 将jdbcTemplate注入到accountDao实例中 -->
		<property name="jdbcTemplate" ref="jdbcTemplate" />
	</bean>
	<bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 配置DataSourceTransactionManager时需要依注入DataSource的引用 -->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    </beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值