com.bixuebihui.dbcon.DatabaseTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of c-dbtools Show documentation
Show all versions of c-dbtools Show documentation
a fast small database connection pool and a active record flavor mini framework
package com.bixuebihui.dbcon;
import java.sql.SQLException;
/**
* DatabaseTools class.
*
* @author xingwx
* @version $Id: $Id
*/
public class DatabaseTools extends BaseOperator
{
/**
* getMaxvalue.
*
* @param tblname a {@link java.lang.String} object.
* @param colname a {@link java.lang.String} object.
* @param condition a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
*/
public String getMaxvalue(String tblname, String colname, String condition) {
String sqlstr = "select MAX("+colname+") from "+tblname;
if(condition != null && condition.length()>3) {
sqlstr = sqlstr + " where "+condition;
}
try {
getResultSet(sqlstr);
if(rst.next()) {
return rst.getString(1);
}
} catch(SQLException sqle) {
System.out.println("SQL [email protected]:"+sqle.getMessage());
} finally {
close();
}
return null;
}
/**
* getMaxnumber.
*
* @param tblname a {@link java.lang.String} object.
* @param colname a {@link java.lang.String} object.
* @param condition a {@link java.lang.String} object.
* @return a int.
*/
public int getMaxnumber(String tblname, String colname, String condition) {
String value = getMaxvalue(tblname, colname, condition);
try {
if(value!=null) {
return Integer.parseInt(value);
}
} catch(NumberFormatException nfe) {
//
}
return -0;
}
/**
* 通过数据库Sequence获得唯一值
*
* @param seq_name 传入的SEQUENCE值
* @return Sequence获得唯一值
*/
public int getNextSequence(String seq_name) {
//CURRVAL
String seqsql = "select "+seq_name+".NEXTVAL from DUAL";
try {
getResultSet(seqsql);
if(rst.next()) {
return rst.getInt(1);
}
} catch(SQLException sqle) {
System.out.println("SQL [email protected]:"+sqle.getMessage());
} finally {
close();
}
return -1;
}
}