package com.wangdonghui.dbcd;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
public class JDBCTest {
private ApplicationContext ctx = null;
private JdbcTemplate jdbcTemplate;
{
ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
System.out.println("fffffffff");
}
@Test
public void test() throws SQLException{
String sql = "insert into people(id,name) values ('5','6')";
int result = jdbcTemplate.update(sql);
System.out.println(result);
}
}
没有空指针,但是到 int result = jdbcTemplate.update(sql);这行代码就不执行也不往下走了,求大神告知
你应该把SQLException catch住,然后打印出error,表people里面的id,你确认是string?
String sql = "insert into people(id,name) values ('5','6')";
int result = jdbcTemplate.update(sql);
一个是Insert,一个又是update??
你在使用junit时,那个条条,是绿色的,还是红色的?
检查下sql呢,如果你id是int类型,不用加''吧!
这种问题就应该debug看下到底是哪个地方出的问题。然后在寻找解决方法
去数据库执行一下那条SQL,可能是数据表锁了