2023年8月3日发(作者:)
javaSQL语句增删改查package
import
import
import
import
*;*;Date;;SimpleDateFormat;public class Xiaofandb { //设备的增加
⼊库 public static void insert() throws Exception { Scanner x = new Scanner(); Shebei sb = new Shebei(); Compy cm = new Compy(); n("请输⼊设备编号"); (t()); n("请输⼊设备名称"); me(()); n("请输⼊设备卡号"); d(()); n("请输⼊设备类型"); e(()); n("请输⼊设备图⽚名称"); g(()); n("请输⼊设备⽣产商"); nd(()); n("请输⼊公司ID"); (t()); n("请输⼊公司名称"); e(()); n("请输⼊公司楼层"); u(()); n("请输⼊公司地址"); ess(()); n("请输⼊公司经纬度"); (()); String sql = "INSERT INTO shebei(sid,sname,card,stype,sjpg,brand) VALUES(?,?,?,?,?,?)"; //准备要执⾏的sql语句 PreparedStatement pst = nection1().prepareStatement(sql); (1, ()); ing(2, me()); ing(3, d()); ing(4, e()); ing(5, g()); ing(6, nd()); int i = eUpdate(); n(i); String sql1 = "INSERT INTO compy(cid,cname,clou,cdress,cjw) VALUes(?,?,?,?,?)"; PreparedStatement pst1 = nection1().prepareStatement(sql1); (1, ()); ing(2, e()); ing(3, u()); ing(4, ess()); ing(5, ()); int i1 = eUpdate(); n(i1); String sql2 = "INSERT INTO anz(sid,cid,date) VALUes(?,?,?)"; PreparedStatement pst2 = nection1().prepareStatement(sql2); (1, ()); (2, ()); Date ad = new Date(); SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str=(ad);
Date hire = (str);Date hr1 = new Date(e()); n(hr1); e(3,hr1); e(3,hr1); } //设备的显⽰ public static void findall() throws Exception { String sql = "SELECT ,,sname,cname,stype,clou,cdress,cjw,sjpg,DATE FROM shebei a,compy b,anz c WHERE = AND ="; PreparedStatement pst = nection1().prepareStatement(sql); ResultSet rt = eQuery(); while(()){ n((1)+" "+(2)+" "+ing(3)+" "+ing(4)+" "+ing(5)+" "+ing(6)+" "+ing(7)+" "+ing(8)+" "+ing(9)+" "+e(10)); } } //查找 public static void find(int a) throws Exception { String sql = "SELECT ,,sname,cname,stype,clou,cdress,cjw,sjpg,DATE FROM shebei a,compy b,anz c WHERE = AND = And =?"; PreparedStatement pst = nection1().prepareStatement(sql); (1,a); ResultSet rt = eQuery(); while(()){ n((1)+" "+(2)+" "+ing(3)+" "+ing(4)+" "+ing(5)+" "+ing(6)+" "+ing(7)+" "+ing(8)+" "+ing(9)+" "+e(10)); } (); (); } // //分页 public static void findall(int page,int pageSize) throws Exception { String sql = "SELECT ,,sname,cname,stype,clou,cdress,cjw,sjpg,DATE FROM shebei a,compy b,anz c WHERE = AND = LIMIT ?,?"; PreparedStatement pst = nection1().prepareStatement(sql); (1,(page-1)*pageSize); (2,pageSize); ResultSet rt = eQuery(); while(()){ n((1)+" "+(2)+" "+ing(3)+" "+ing(4)+" "+ing(5)+" "+ing(6)+" "+ing(7)+" "+ing(8)+" "+ing(9)+" "+e(10)); } (); (); } //删除 public static void del(int a) throws Exception { String sql = "delete from anz where sid = ?"; String sql1 = "delete from shebei where sid = ?"; PreparedStatement pst = nection1().prepareStatement(sql); (1,a); PreparedStatement pst1 = nection1().prepareStatement(sql); (1,a); (); (); } //修改 public static void alt(int a) throws Exception { String sql = "update anz set date=? where sid=?"; PreparedStatement pst = nection1().prepareStatement(sql); Date ad = new Date(); SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str=(ad);
Date hire = (str);Date hr1 = new Date(e()); Date hr1 = new Date(e()); n(hr1); e(1,hr1); (2,a); int i = eUpdate(); (); } //分页 public static void select(int page,int pageSize) throws Exception { String sql1 = "SELECT * FROM day1 LIMIT ?,?"; Connection con = nection1(); //创建执⾏sql的对象 statement PreparedStatement st = eStatement(sql1); (1, (page - 1) * pageSize); (2, pageSize); ResultSet rs = eQuery(); while (()) { n(ing(1) + " " + (2)); } (rs, st, con); } //菜单 public static void Mean() throws Exception { Scanner x = new Scanner(); int b = 0; while(true){ n("1 安装设备"); n("2 查看设备"); n("3 查找设备"); n("4 修改设备"); n("5 分页查找"); n("6 退出"); int c = t(); switch (c){ case 0: b=1; break; case 1: insert(); break; case 2: findall(); break; case 3: n("请输⼊查找的设备号:"); int a = t(); find(a); break; case 4: n("请输⼊修改的设备号:"); int a1 = t(); alt(a1); case 5: n("开始位置"); int a3 = t(); n("分页⼤⼩"); int a4 = t(); findall(a3,a4); break; } if(b==1){ break; } } } } public static void main(String[] args) throws Exception{ Mean(); }}
2023年8月3日发(作者:)
javaSQL语句增删改查package
import
import
import
import
*;*;Date;;SimpleDateFormat;public class Xiaofandb { //设备的增加
⼊库 public static void insert() throws Exception { Scanner x = new Scanner(); Shebei sb = new Shebei(); Compy cm = new Compy(); n("请输⼊设备编号"); (t()); n("请输⼊设备名称"); me(()); n("请输⼊设备卡号"); d(()); n("请输⼊设备类型"); e(()); n("请输⼊设备图⽚名称"); g(()); n("请输⼊设备⽣产商"); nd(()); n("请输⼊公司ID"); (t()); n("请输⼊公司名称"); e(()); n("请输⼊公司楼层"); u(()); n("请输⼊公司地址"); ess(()); n("请输⼊公司经纬度"); (()); String sql = "INSERT INTO shebei(sid,sname,card,stype,sjpg,brand) VALUES(?,?,?,?,?,?)"; //准备要执⾏的sql语句 PreparedStatement pst = nection1().prepareStatement(sql); (1, ()); ing(2, me()); ing(3, d()); ing(4, e()); ing(5, g()); ing(6, nd()); int i = eUpdate(); n(i); String sql1 = "INSERT INTO compy(cid,cname,clou,cdress,cjw) VALUes(?,?,?,?,?)"; PreparedStatement pst1 = nection1().prepareStatement(sql1); (1, ()); ing(2, e()); ing(3, u()); ing(4, ess()); ing(5, ()); int i1 = eUpdate(); n(i1); String sql2 = "INSERT INTO anz(sid,cid,date) VALUes(?,?,?)"; PreparedStatement pst2 = nection1().prepareStatement(sql2); (1, ()); (2, ()); Date ad = new Date(); SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str=(ad);
Date hire = (str);Date hr1 = new Date(e()); n(hr1); e(3,hr1); e(3,hr1); } //设备的显⽰ public static void findall() throws Exception { String sql = "SELECT ,,sname,cname,stype,clou,cdress,cjw,sjpg,DATE FROM shebei a,compy b,anz c WHERE = AND ="; PreparedStatement pst = nection1().prepareStatement(sql); ResultSet rt = eQuery(); while(()){ n((1)+" "+(2)+" "+ing(3)+" "+ing(4)+" "+ing(5)+" "+ing(6)+" "+ing(7)+" "+ing(8)+" "+ing(9)+" "+e(10)); } } //查找 public static void find(int a) throws Exception { String sql = "SELECT ,,sname,cname,stype,clou,cdress,cjw,sjpg,DATE FROM shebei a,compy b,anz c WHERE = AND = And =?"; PreparedStatement pst = nection1().prepareStatement(sql); (1,a); ResultSet rt = eQuery(); while(()){ n((1)+" "+(2)+" "+ing(3)+" "+ing(4)+" "+ing(5)+" "+ing(6)+" "+ing(7)+" "+ing(8)+" "+ing(9)+" "+e(10)); } (); (); } // //分页 public static void findall(int page,int pageSize) throws Exception { String sql = "SELECT ,,sname,cname,stype,clou,cdress,cjw,sjpg,DATE FROM shebei a,compy b,anz c WHERE = AND = LIMIT ?,?"; PreparedStatement pst = nection1().prepareStatement(sql); (1,(page-1)*pageSize); (2,pageSize); ResultSet rt = eQuery(); while(()){ n((1)+" "+(2)+" "+ing(3)+" "+ing(4)+" "+ing(5)+" "+ing(6)+" "+ing(7)+" "+ing(8)+" "+ing(9)+" "+e(10)); } (); (); } //删除 public static void del(int a) throws Exception { String sql = "delete from anz where sid = ?"; String sql1 = "delete from shebei where sid = ?"; PreparedStatement pst = nection1().prepareStatement(sql); (1,a); PreparedStatement pst1 = nection1().prepareStatement(sql); (1,a); (); (); } //修改 public static void alt(int a) throws Exception { String sql = "update anz set date=? where sid=?"; PreparedStatement pst = nection1().prepareStatement(sql); Date ad = new Date(); SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str=(ad);
Date hire = (str);Date hr1 = new Date(e()); Date hr1 = new Date(e()); n(hr1); e(1,hr1); (2,a); int i = eUpdate(); (); } //分页 public static void select(int page,int pageSize) throws Exception { String sql1 = "SELECT * FROM day1 LIMIT ?,?"; Connection con = nection1(); //创建执⾏sql的对象 statement PreparedStatement st = eStatement(sql1); (1, (page - 1) * pageSize); (2, pageSize); ResultSet rs = eQuery(); while (()) { n(ing(1) + " " + (2)); } (rs, st, con); } //菜单 public static void Mean() throws Exception { Scanner x = new Scanner(); int b = 0; while(true){ n("1 安装设备"); n("2 查看设备"); n("3 查找设备"); n("4 修改设备"); n("5 分页查找"); n("6 退出"); int c = t(); switch (c){ case 0: b=1; break; case 1: insert(); break; case 2: findall(); break; case 3: n("请输⼊查找的设备号:"); int a = t(); find(a); break; case 4: n("请输⼊修改的设备号:"); int a1 = t(); alt(a1); case 5: n("开始位置"); int a3 = t(); n("分页⼤⼩"); int a4 = t(); findall(a3,a4); break; } if(b==1){ break; } } } } public static void main(String[] args) throws Exception{ Mean(); }}
发布评论