📄 nationalshipdao.java
字号:
/**
* Copyright 2007 Wuhan University of Technology.
* All right reserved.
* Create on 2007-3-24
*/
package edu.whut.cwts.maintain.action;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import edu.whut.cwts.datasource.DBConnect;
import edu.whut.cwts.maintain.bean.Ship;
import edu.whut.cwts.maintain.util.DateUtil;
/**
* @author dwr
*
*/
public class NationalShipDAO {
public static Map checkShipInfo(String selectShip,String ship1)
{
String shipinfo=ship1.trim();
Map shipmap = new HashMap();
String count="";
String sql="";
String sql1="";
if(selectShip.trim().equals("1")){
sql="select cjdjh,cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh from cbxxb where cmch='"+shipinfo+"' ";
sql1="select count(*) from cbxxb where cmch='"+shipinfo+"' ";
}
else if(selectShip.trim().equals("2")){
sql="select cjdjh,cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh from cbxxb where cjdjh='"+shipinfo+"' ";
sql1="select count(*) from cbxxb where cjdjh='"+shipinfo+"' ";
}
DBConnect dbconn1=new DBConnect();
try
{
ResultSet rs1 = dbconn1.executeQuery(sql1);
if(rs1.next()){
count=String.valueOf(rs1.getInt(1));
shipmap.put("count",count);}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn1.close();
DBConnect dbconn=new DBConnect();
try
{
ResultSet rs = dbconn.executeQuery(sql);
while(rs.next())
{
Ship ship = new Ship();
ship.setCjdjh(rs.getString("cjdjh"));
ship.setCmch(rs.getString("cmch"));
ship.setGsdm(rs.getString("gsdm"));
ship.setCz(rs.getString("cz"));
ship.setCzsfzh(rs.getString("czsfzh"));
ship.setGl(rs.getFloat("gl"));
ship.setJd(rs.getFloat("jd"));
ship.setZd(rs.getFloat("zd"));
ship.setZzd(rs.getFloat("zzd"));
ship.setCjg(rs.getString("cjg"));
ship.setSfyy(rs.getString("sfyy"));
ship.setYyzh(rs.getString("yyzh"));
shipmap.put("ship",ship);
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn.close();
return shipmap;
}
public static Ship getNationalShip(String cjdjh)
{
Ship nationalship = new Ship();
DBConnect dbconn=new DBConnect();
String sql = "select cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh from cbxxb ";
sql += "WHERE ";
sql += "cjdjh = '" + cjdjh.trim()+ "' ";
try
{
ResultSet rs = dbconn.executeQuery(sql);
while(rs.next())
{
nationalship.setCmch(rs.getString("cmch"));
nationalship.setGsdm(rs.getString("gsdm"));
nationalship.setCz(rs.getString("cz"));
nationalship.setCzsfzh(rs.getString("czsfzh"));
nationalship.setGl(rs.getFloat("gl"));
nationalship.setJd(rs.getFloat("jd"));
nationalship.setZd(rs.getFloat("zd"));
nationalship.setZzd(rs.getFloat("zzd"));
nationalship.setCjg(rs.getString("cjg"));
nationalship.setSfyy(rs.getString("sfyy"));
nationalship.setYyzh(rs.getString("yyzh"));
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn.close();
return nationalship;
}
public static boolean addNationalShip(String cjdjh,String cmch,String gsdm,String cz,String czsfzh,String gl,String jd,String zd,String zzd,String cjg,String sfyy,String yyzh)
{
boolean flag=false;
String date = DateUtil.formatTime(new Date());
float power = Float.parseFloat(gl.trim());
float justton = Float.parseFloat(jd.trim());
float grosston = Float.parseFloat(zd.trim());
float deadweightton = Float.parseFloat(zzd.trim());
System.out.println(gsdm.trim()+"qqqq");
String sqlinsert="";
DBConnect dbconn=new DBConnect();
if(gsdm.trim().equals("")||gsdm.trim().equals(null)){
System.out.println("xx");
sqlinsert = "INSERT INTO cbxxb(cjdjh,cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh,xgsj)";
sqlinsert +="VALUES( ";
sqlinsert += " '" + cjdjh.trim() + "' ,";
sqlinsert += " '" + cmch.trim() + "' ,";
sqlinsert += " NULL ,";
sqlinsert += " '" + cz.trim() + "' ,";
sqlinsert += " '" + czsfzh.trim() + "', ";
sqlinsert += " " + power + " ,";
sqlinsert += " " + justton + " ,";
sqlinsert += " " + grosston + " ,";
sqlinsert += " " + deadweightton + " ,";
sqlinsert += " '" + cjg.trim() + "', ";
sqlinsert += " '" + sfyy.trim() + "' ,";
sqlinsert += " '" + yyzh.trim() + "' ,";
sqlinsert += " '" + date + "' )";}
else{
System.out.println("yy");
sqlinsert = "INSERT INTO cbxxb(cjdjh,cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh,xgsj)";
sqlinsert +="VALUES( ";
sqlinsert += " '" + cjdjh.trim() + "' ,";
sqlinsert += " '" + cmch.trim() + "' ,";
sqlinsert += " '" + gsdm.trim() + "' ,";
sqlinsert += " '" + cz.trim() + "' ,";
sqlinsert += " '" + czsfzh.trim() + "', ";
sqlinsert += " " + power + " ,";
sqlinsert += " " + justton + " ,";
sqlinsert += " " + grosston + " ,";
sqlinsert += " " + deadweightton + " ,";
sqlinsert += " '" + cjg.trim() + "', ";
sqlinsert += " '" + sfyy.trim() + "' ,";
sqlinsert += " '" + yyzh.trim() + "' ,";
sqlinsert += " '" + date + "' )";}
System.out.println(sqlinsert);
try
{
flag = dbconn.executeInsert(sqlinsert);
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
System.out.println(sqlinsert);
}
dbconn.close();
return flag;
}
public static boolean addShipTransaction(String cjdjh,String cmch,String gsdm,String cz,String czsfzh,String gl,String jd,String zd,String zzd,String cjg,String sfyy,String yyzh,String xgrdm)
{
boolean flag=false;
String date = DateUtil.formatTime(new Date());
float power = Float.parseFloat(gl.trim());
float justton = Float.parseFloat(jd.trim());
float grosston = Float.parseFloat(zd.trim());
float deadweightton = Float.parseFloat(zzd.trim());
String year=date.substring(0,4);
String sql1="select cast(isnull(max (ydxh),'"+year+"00000') as int)+1 from cbydb where ydxh like '"+year+"%'";
DBConnect dbconn1=new DBConnect();
String ydxh="";
try
{
ResultSet rs1 = dbconn1.executeQuery(sql1);
if(rs1.next())
ydxh=rs1.getString(1);
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn1.close();
DBConnect dbconn=new DBConnect();
String sqlinsert = "INSERT INTO cbydb(ydxh,cjdjh,cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh,xgsj,xgrdm)";
sqlinsert +="VALUES( ";
sqlinsert += " '" + ydxh + "' ,";
sqlinsert += " '" + cjdjh.trim() + "' ,";
sqlinsert += " '" + cmch.trim() + "' ,";
if(gsdm.trim().equals("")||gsdm.trim().equals(null))
sqlinsert += "NULL,";
else
sqlinsert += " '" + gsdm.trim() + "' ,";
sqlinsert += " '" + cz.trim() + "' ,";
sqlinsert += " '" + czsfzh.trim() + "', ";
sqlinsert += " " + power + " ,";
sqlinsert += " " + justton + " ,";
sqlinsert += " " + grosston + " ,";
sqlinsert += " " + deadweightton + " ,";
sqlinsert += " '" + cjg.trim() + "', ";
sqlinsert += " '" + sfyy.trim() + "' ,";
sqlinsert += " '" + yyzh.trim() + "' ,";
sqlinsert += " '" + date + "' ,";
sqlinsert += " '" + xgrdm.trim() + "' )";
System.out.println(sqlinsert);
try
{
flag = dbconn.executeInsert(sqlinsert);
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
System.out.println(sqlinsert);
}
dbconn.close();
return flag;
}
public boolean deleteNationalShip(String cjdjh)
{
String sql="delete cbxxb where cjdjh='"+cjdjh.trim()+"'";
System.out.println(sql);
DBConnect dbconn2=new DBConnect();
boolean flag=false;
flag = dbconn2.executeDelete(sql);
//System.out.println(flag);
dbconn2.close();
return flag;
}
public int updateNationalShip(String cjdjh,String cmch,String gsdm,String cz,String czsfzh,String gl,String jd,String zd,String zzd,String cjg,String sfyy,String yyzh)
{
String date = DateUtil.formatTime(new Date());
float power = Float.parseFloat(gl.trim());
float justton = Float.parseFloat(jd.trim());
float grosston = Float.parseFloat(zd.trim());
float deadweightton = Float.parseFloat(zzd.trim());
String sql="update cbxxb set";
sql += " cmch= '" + cmch.trim() + "' ,";
if(gsdm.trim().equals("")||gsdm.trim().equals(null))
sql += " gsdm= NULL ,";
else
sql += " gsdm= '" + gsdm.trim() + "' ,";
sql += " cz= '" + cz.trim() + "' ,";
sql += " czsfzh= '" + czsfzh.trim() + "', ";
sql += " gl= " + power + " ,";
sql += " jd= " + justton + " ,";
sql += " zd= " + grosston + " ,";
sql += " zzd= " + deadweightton + " ,";
sql += " cjg= '" + cjg.trim() + "', ";
sql += " sfyy= '" + sfyy.trim() + "' ,";
sql += " yyzh= '" + yyzh.trim() + "' ,";
sql += " xgsj= '" + date + "' ";
sql += "where cjdjh='"+cjdjh.trim()+"' ";
System.out.println(sql);
DBConnect dbconn = new DBConnect();
int flag=0;
try {
flag = dbconn.executeUpdate(sql);
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn.close();
//System.out.println(flag);
return flag;
}
public static void main(String[] args) {
// TODO 自动生成方法存根
System.out.println("dd11111111");
String cjdjh="3";
String cmch= "1";
String gsdm= "";
String cz= "1";
String czsfzh= "1";
String gl= "1";
String jd= "1";
String zd= "1";
String zzd= "1";
String cjg= "1";
String sfyy= "1";
String yyzh= "1";
boolean flag;
System.out.println("dd11");
flag=addNationalShip(cjdjh,cmch,gsdm,cz,czsfzh,gl,jd,zd,zzd,cjg,sfyy,yyzh);
System.out.println(flag);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -