java 执行sql语句返回值为NULL
//JUNIT测试类@Testpublicvoidtesticmaxnum(){IcMaxNumDAOnumdao=newIcMaxNumImpl();IcMaxNumn...
//JUNIT测试类
@Test
public void testicmaxnum(){
IcMaxNumDAO numdao = new IcMaxNumImpl();
IcMaxNum num = new IcMaxNum();
num.setFTableName("'poorder'");
//出错的在这里,返回值为NULL
System.out.println(numdao.geticmaxnum(num.getFTableName()));
}
//实现类
public class IcMaxNumImpl extends DAO<IcMaxNum> implements IcMaxNumDAO{
@Override
public IcMaxNum geticmaxnum(String fTableName) {
String sql="select fmaxnum from icmaxnum "
+ "where ftablename = ?";
return get(sql, fTableName);
}
}
//业务DAO
public interface IcMaxNumDAO {
public IcMaxNum geticmaxnum(String fTableName);
}
//实体类
public class IcMaxNum {
//无参构造方法
public IcMaxNum() {
}
public void setFTableName(String fTableName) {
this.fTableName = fTableName;
}
public String getFTableName() {
return fTableName;
}
public void setFMaxNum(int fMaxNum) {
this.fMaxNum = fMaxNum;
}
public int getFMaxNum() {
return fMaxNum;
}
private String fTableName;
private int fMaxNum;
public IcMaxNum(String fTableName, int fMaxNum) {
super();
this.fTableName = fTableName;
this.fMaxNum = fMaxNum;
}
@Override
public String toString() {
return "IcMaxNum [fTableName=" + fTableName + ", fMaxNum=" + fMaxNum
+ "]";
}
}
//DAO
public class DAO<T> {
private QueryRunner queryRunner=new QueryRunner(true);
private Class<T> clazz;
public DAO() {
Type supperClass= getClass().getGenericSuperclass();
if(supperClass instanceof ParameterizedType){
ParameterizedType parameterizedType=(ParameterizedType)supperClass;
Type [] typeArgs= parameterizedType.getActualTypeArguments();
if(typeArgs!=null && typeArgs.length>0){
if(typeArgs[0] instanceof Class){
clazz=(Class<T>) typeArgs[0];
}
}
}
}
@param sql
* @param args
* @return
*/
public T get(String sql,Object...args){
Connection connection=null;
try {
connection=JdbcUtils.getConnection();
return queryRunner.query(connection, sql, new BeanHandler<>(clazz), args);
} catch (Exception e) {
e.printStackTrace();
}finally{
JdbcUtils.releaseConnection(connection);
}
return null;
}
} 展开
@Test
public void testicmaxnum(){
IcMaxNumDAO numdao = new IcMaxNumImpl();
IcMaxNum num = new IcMaxNum();
num.setFTableName("'poorder'");
//出错的在这里,返回值为NULL
System.out.println(numdao.geticmaxnum(num.getFTableName()));
}
//实现类
public class IcMaxNumImpl extends DAO<IcMaxNum> implements IcMaxNumDAO{
@Override
public IcMaxNum geticmaxnum(String fTableName) {
String sql="select fmaxnum from icmaxnum "
+ "where ftablename = ?";
return get(sql, fTableName);
}
}
//业务DAO
public interface IcMaxNumDAO {
public IcMaxNum geticmaxnum(String fTableName);
}
//实体类
public class IcMaxNum {
//无参构造方法
public IcMaxNum() {
}
public void setFTableName(String fTableName) {
this.fTableName = fTableName;
}
public String getFTableName() {
return fTableName;
}
public void setFMaxNum(int fMaxNum) {
this.fMaxNum = fMaxNum;
}
public int getFMaxNum() {
return fMaxNum;
}
private String fTableName;
private int fMaxNum;
public IcMaxNum(String fTableName, int fMaxNum) {
super();
this.fTableName = fTableName;
this.fMaxNum = fMaxNum;
}
@Override
public String toString() {
return "IcMaxNum [fTableName=" + fTableName + ", fMaxNum=" + fMaxNum
+ "]";
}
}
//DAO
public class DAO<T> {
private QueryRunner queryRunner=new QueryRunner(true);
private Class<T> clazz;
public DAO() {
Type supperClass= getClass().getGenericSuperclass();
if(supperClass instanceof ParameterizedType){
ParameterizedType parameterizedType=(ParameterizedType)supperClass;
Type [] typeArgs= parameterizedType.getActualTypeArguments();
if(typeArgs!=null && typeArgs.length>0){
if(typeArgs[0] instanceof Class){
clazz=(Class<T>) typeArgs[0];
}
}
}
}
@param sql
* @param args
* @return
*/
public T get(String sql,Object...args){
Connection connection=null;
try {
connection=JdbcUtils.getConnection();
return queryRunner.query(connection, sql, new BeanHandler<>(clazz), args);
} catch (Exception e) {
e.printStackTrace();
}finally{
JdbcUtils.releaseConnection(connection);
}
return null;
}
} 展开
展开全部
问一下,你的数据库是什么?
ftablename的字段类型是什么?
ftablename的字段类型是什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
打断点,跟踪
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有可能抛出异常
更多追问追答
追问
运行的时候没抛出异常。
追答
首选用sql查询数据库,如果能查到,说明数据源没连接到;查不到,说明sql错误。另外e.printStackTrace();未必会打出来,需要使用log4j打印。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |