📄 selectinfomodel.java
字号:
/*
* Created on 2005-4-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package ddl.model;
import java.sql.*;
import java.util.Date;
import java.text.DateFormat;
import zhangchunliang.model.AppMode;
import kangyi.ConnectionPool.DbConnection;
/**
* @author duzhibo@neusoft
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class SelectInfoModel {
DbConnection db=null;
Connection con=null;
/** 构造方法 连接数据库 */
//public SelectInfoModel() {
//try {
// Class.forName("com.mysql.jdbc.Driver");
//} catch (ClassNotFoundException e) {
// e.getMessage();
//}
//}
/**
* name: 排序 describing: 按照航空公司或航班号排序
*
* @param CountryManagerForm
* cmf
* @return StringBuffer buffer 返回按照航空公司或航班号排序好的表 两种情况:按照航空公司排序或者按照航班号排序
*/
public String change(String s) {
String str = s;
try {
byte b[] = str.getBytes("ISO-8859-1");
str = new String(b);
return str;
} catch (Exception e) {
return str;
}
}
/**
* name: 生成系统时间 静态方法 不用实例化直接调用 属于类方法
*/
public static String nowDate() {
/** 系统时间变量 */
Date nowdate = new Date();
/** 格式化后时间变量 */
String formatDate;
/** 格式化为"YYYY-MM-DD" */
formatDate = DateFormat.getDateInstance().format(nowdate);
return formatDate;
}
/** 生成系统时间 */
String insert_date = nowDate();
/** 生成系统时间 */
String update_date = nowDate();
/** 定义一个fno的变量来接受form中的fno */
public String fno;
/** 定义排序的方法 */
public StringBuffer selectInfoAction(String str) {
AppMode.registerUser();
/** 定义一个 StringBuffer对象,来存放连接的信息 */
//StringBuffer conSql = new StringBuffer(500);
//conSql.append("jdbc:mysql://192.168.219.148/ciqms?user=");
//conSql.append("ddl");
//conSql.append("&password=");
//conSql.append("223754301809");
//conSql.append("&useUnicode=true&characterEncoding=GBK");
//String conmysql = conSql.toString();
/** 声明数据库的连接变量 */
//Connection con = null;
Statement sql = null;
ResultSet rs = null;
String selectmethod = change(str);
StringBuffer buffer = new StringBuffer();
try {
//con = DriverManager.getConnection(conmysql);
db=new DbConnection();
con=db.getCon();
sql = con.createStatement();
/** 绘制表头 */
buffer.append("<Table Border>");
buffer.append("<tr>");
buffer.append("<TH width=100>" + "航空公司");
buffer.append("<TH width=100>" + "航班号");
buffer.append("</tr>");
if (selectmethod.equals("航空公司排序")) {
rs = sql.executeQuery("select * from flightcom order by fcom");
while (rs.next()) {
buffer.append("<tr>");
buffer.append("<td >" + rs.getString(2) + "</td>");
buffer.append("<td >" + rs.getString(1) + "</td>");
buffer
.append("<td><input type=\"radio\" name=\"fno\" value=\""
+ rs.getString(1) + "\"></td>");
buffer.append("</tr>");
}
buffer.append("</Table>");
con.close();
AppMode.loginoutUser();
return buffer;
} else if (selectmethod.equals("航班号排序")) {
rs = sql.executeQuery("select * from flightcom order by fno");
while (rs.next()) {
buffer.append("<tr>");
buffer.append("<td >" + rs.getString(2) + "</td>");
buffer.append("<td >" + rs.getString(1) + "</td>");
buffer
.append("<td><input type=\"radio\" name=\"fno\" value=\""
+ rs.getString(1) + "\"></td>");
buffer.append("</tr>");
}
buffer.append("</Table>");
con.close();
AppMode.loginoutUser();
return buffer;
} else{
AppMode.loginoutUser();
return buffer;
}
}
catch (Exception e) {
AppMode.loginoutUser();
return new StringBuffer("无法建立连接!");
}
}
/**
* name: 一览页面中的航空公司与航班号信息删除 describing: VIEW页中删除flightcom表中信息
*/
public boolean viewDelete(String fno) {
AppMode.registerUser();
//StringBuffer conSql = new StringBuffer(500);
//conSql.append("jdbc:mysql://192.168.219.148/ciqms?user=");
// conSql.append("ddl");
// conSql.append("&password=");
//conSql.append("223754301809");
//conSql.append("&useUnicode=true&characterEncoding=GBK");
//String conmysql = conSql.toString();
/** 获得FORM里的参数 */
boolean b = true;
//Connection con = null;
Statement sql = null;
ResultSet rs = null;
String no = change(fno);
try {
//con = DriverManager.getConnection(conmysql);
db=new DbConnection();
con=db.getCon();
sql = con.createStatement();
if (no != null) {
String condition = "delete from flightcom where fno='" + no
+ "'";
sql.executeUpdate(condition);
con.close();
AppMode.loginoutUser();
return b;
} else{
AppMode.loginoutUser();
return false;
}
} catch (SQLException e) {
AppMode.loginoutUser();
System.out.print(e.getMessage());
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -