Java、XML与数据库编程实践(四)
2008-01-05 20:10:37 来源:WEB开发网[系列文章:Java、XML与数据库编程实践(二)]
[系列文章:Java、XML与数据库编程实践(三)]
PRotected boolean alreadyin(String tname,String colname, String value)
{
int result;
ResultSet rst=null;
try {
//执行SQL语句
String query = "select "+colname+" from "+tname+" where "+colname+"='"+value+"'";
Statement statement = connformax.createStatement();
rst = statement.executeQuery( query );
if(rst.next())
{
statement.close();
rst.close();
return true;
}
}
catch ( SQLException sqlex ) {
sqlex.printStackTrace();
return false;
}
return false;
}
protected int getIdfromNumber(String tname,String colname, String value)
{
int result;
ResultSet rst=null;
try {
Connection conn= DriverManager.getConnection( destPara.getUrl(), destPara.getUsername(),destPara.getPassWord());
String query = "select id,"+colname+" from "+tname+" where "+colname+"='"+value+"'";
System.out.println(query);
Statement statement = conn.createStatement();
rst = statement.executeQuery( query );
if(rst.next())
{
return rst.getInt("id");
}
}
catch ( SQLException sqlex ) {
sqlex.printStackTrace();
return 0;
}
return 0;
}
/**
* 得到某个表中的最大的id号
*/
更多精彩
赞助商链接