📄 internationalshipdao.java
字号:
/**
* Copyright 2007 Wuhan University of Technology.
* All right reserved.
* Create on 2007-3-26
*/
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.InternationalShip;
import edu.whut.cwts.maintain.util.DateUtil;
/**
* @author dwr
*
*/
public class InternationalShipDAO {
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,gl,jd,zd,zzd,cjg,sfyy,yyzh from gjcbb where cmch='"+shipinfo+"' ";
sql1="select count(*) from gjcbb where cmch='"+shipinfo+"' ";
}
else if(selectShip.trim().equals("2")){
sql="select cjdjh,cmch,gl,jd,zd,zzd,cjg,sfyy,yyzh from gjcbb where cjdjh='"+shipinfo+"' ";
sql1="select count(*) from gjcbb where cjdjh='"+shipinfo+"' ";
}
System.out.println(sql);
System.out.println(sql1);
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())
{
InternationalShip ship = new InternationalShip();
ship.setRegisterID(rs.getString("cjdjh"));
ship.setShipID(rs.getString("cmch"));
ship.setPower(rs.getFloat("gl"));
ship.setJustton(rs.getFloat("jd"));
ship.setGrosston(rs.getFloat("zd"));
ship.setDeadweightton(rs.getFloat("zzd"));
ship.setHomeport(rs.getString("cjg"));
ship.setIsoperating(rs.getString("sfyy"));
ship.setOperatingID(rs.getString("yyzh"));
shipmap.put("ship",ship);
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn.close();
return shipmap;
}
public static InternationalShip getNationalShip(String cmch)
{
InternationalShip internationalship = new InternationalShip();
DBConnect dbconn=new DBConnect();
String sql = "select cjdjh,cmch,gl,jd,zd,zzd,cjg,sfyy,yyzh from gjcbb ";
sql += "WHERE ";
sql += "cmch = '" + cmch.trim()+ "' ";
try
{
ResultSet rs = dbconn.executeQuery(sql);
while(rs.next())
{
internationalship.setRegisterID(rs.getString("cjdjh"));
internationalship.setShipID(rs.getString("cmch"));
internationalship.setPower(rs.getFloat("gl"));
internationalship.setJustton(rs.getFloat("jd"));
internationalship.setGrosston(rs.getFloat("zd"));
internationalship.setDeadweightton(rs.getFloat("zzd"));
internationalship.setHomeport(rs.getString("cjg"));
internationalship.setIsoperating(rs.getString("sfyy"));
internationalship.setOperatingID(rs.getString("yyzh"));
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn.close();
return internationalship;
}
public static boolean addInternationalShip(String cjdjh,String cmch,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());
DBConnect dbconn=new DBConnect();
String sqlinsert = "INSERT INTO gjcbb(cjdjh,cmch,gl,jd,zd,zzd,cjg,sfyy,yyzh,xgsj,xgrdm)";
sqlinsert +="VALUES( ";
sqlinsert += " '" + cjdjh.trim() + "' ,";
sqlinsert += " '" + cmch.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 static boolean addShipTransaction(String cjdjh,String cmch,String gl,String jd,String zd,String zzd,String cjg,String sfyy,String yyzh,String xgrdm)
{
boolean flag=false;
System.out.println(xgrdm);
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 (gjydxh),'"+year+"00000') as int)+1 from gjcbydb where gjydxh like '"+year+"%'";
DBConnect dbconn1=new DBConnect();
String gjydxh="";
try
{
ResultSet rs1 = dbconn1.executeQuery(sql1);
if(rs1.next())
gjydxh=rs1.getString(1);
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
dbconn1.close();
DBConnect dbconn=new DBConnect();
String sqlinsert = "INSERT INTO gjcbydb(gjydxh,cjdjh,cmch,gl,jd,zd,zzd,cjg,sfyy,yyzh,xgsj,xgrdm)";
sqlinsert +="VALUES( ";
sqlinsert += " '" + gjydxh + "' ,";
sqlinsert += " '" + cjdjh.trim() + "' ,";
sqlinsert += " '" + cmch.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 deleteInternationalShip(String cmch)
{
String sql="delete gjcbb where cmch='"+cmch.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 updateInternationalShip(String cjdjh,String cmch,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 gjcbb set";
sql += " cjdjh='"+cjdjh.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 cmch= '" + cmch.trim() + "'";
System.out.println(sql);
DBConnect dbconn = new DBConnect();
int flag=0;
try {
flag = dbconn.executeUpdate(sql);
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
//System.out.println(flag);
dbconn.close();
return flag;
}
public static void main(String[] args) {
// TODO 自动生成方法存根
/*System.out.println("dd11111111");
String cjdjh="2";
String cmch= "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=addInternationalShip(cjdjh,cmch,gl,jd,zd,zzd,cjg,sfyy,yyzh,"2");
System.out.println(flag);*/
String count=(String) checkShipInfo("1","1").get("count");
System.out.println(count);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -