📄 dodata.java
字号:
package com.mdcl.mocha.jlcmcc.interfaceforWS;
import com.mdcl.mocha.jlcmcc.DBconnection.DBConnectionManager;
import java.sql.*;
/**
* <strong>Title : DoData<br></strong>
* <strong>Description : 查询数据库生成下拉框 </strong><br>
* <strong>Create on : 2007-9-24<br></strong>
* <p>
* <strong>Copyright (C) Mocha Software Co.,Ltd.<br></strong>
* <p>
* @author zhanghd zhanghd@mochasoft.com.cn<br>
* @version <strong>吉林移动BPM一期</strong><br>
* <br>
* <strong>修改历史:</strong><br>
* 修改人 修改日期 修改描述<br>
* -------------------------------------------<br>
* <br>
* <br>
*/
public class DoData
{
/**
*Desc:将表中某一类型关键字的信息在下拉列表框中显示
* @param myValue:String 业务表中该关键字的值
* @param keyTable:String 关键字表名
* @param primaryField:String 关键字表的主键
* @param nameField:String 关键字表的名字字段
* @param flagField:String 类型标识字段
* @param flagValue:String 类型标识值
* @return String 转化后的数组字符串
*/
public String getDynamicOption(String myValue, String keyTable, String primaryField, String nameField, String flagField, String flagValue)
{
String result;
ResultSet rsThis = null;
result = "";
String primaryValue = "";
String nameValue = "";
DBConnectionManager db = null;
Connection con = null;
Statement stmt = null;
// 数据库查询语句
String strSql = "select * from " + keyTable + " where " + flagField;
if(flagValue != null)
strSql = strSql + " = '" + flagValue + "'";
else
strSql = strSql + " is null ";
try
{
boolean isHasDefault = false;
db = DBConnectionManager.getInstance();
con = db.getConnection("idb");
stmt = con.createStatement();
//生成下拉框字符串
for(rsThis = stmt.executeQuery(strSql); rsThis.next();)
{
primaryValue = getString(rsThis, primaryField);
nameValue = getString(rsThis, nameField);
result = result + "<option value=" + primaryValue;
if(primaryValue.equals(myValue))
{
result = result + " selected";
isHasDefault = true;
}
result = result + ">" + nameValue + "</option>";
}
if(!isHasDefault)
result = "<option value='' selected>--请选择--</option>" + result;
}
catch(Exception e)
{
result = "";
System.out.println(e.toString());
e.printStackTrace();
}
finally
{
db.freeConnection("idb", con);
}
return result;
}
/**
* 提供从CachedRowSet中取得数据的函数,如果为null,返回的为“”
* @param crs CachedRowSet
* @param str 字段名称字符串
* @return
*/
public static String getString(ResultSet rs, String str)
{
String temp = null;
try
{
temp = rs.getString(str);
}
catch(SQLException e)
{
e.printStackTrace();
}
if(temp != null && !temp.equals("null"))
return temp;
else
return "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -