package com.bn.serverinfo;//声明包语句
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class DBUtil{ //创建主类
public static Connection getConnection(){ //编写与数据库建立连接的方法
Connection con = null; //声明连接
try{
Class.forName("org.gjt.mm.mysql.Driver"); //声明驱动
con = DriverManager.getConnection("jdbc:mysql://localhost/orderdish?useUnicode=true&characterEncoding=UTF-8","root","");//得到连接(数据库名,编码形式,数据库用户名,数据库密码)
}catch(Exception e){
e.printStackTrace(); //捕获异常
}
return con; //返回连接
}
//根据员工的姓名得到id
public static String getWorkeridByname(String string){
Connection con = getConnection();//与数据库建立连接
Statement st = null;//创建接口
ResultSet rs = null;//结果集
String str = null;//字符串常量
try{
st = con.createStatement();//创建一个对象来将SQL语句发送到数据库
String task = "select w_id from WorkerInfo where w_name='"+string+"';";//编写SQL语句
rs = st.executeQuery(task);//执行SQL语句
rs.next(); //遍历执行
str=rs.getString(1); //将查询得到的员工ID放入字符串常量
}
catch(Exception e){ //捕获异常,返回空值
e.printStackTrace();
return null;
}
finally{
try {rs.close();} catch (SQLException e) {e.printStackTrace();}//结果集
try {st.close();} catch (SQLException e) {e.printStackTrace();}
try {con.close();} catch (SQLException e) {e.printStackTrace();}
}
return str; //返回员工ID
}
//得到计量单位的信息
public static List<String[]> getCU(){
Connection con = getConnection();//与数据库建立连接
Statement st = null;//创建接口
ResultSet rs = null;//结果集
List<String[]>ll=new ArrayList<String[]>();//创建存放数据的列表
try{
st=con.createStatement();//创建一个对象来将SQL语句发送到数据库
String sql="select unit_id,unit_name,unit_remark from CountUnit where unit_delflg='"+0+"'";//编写SQL语句
rs=st.executeQuery(sql);//执行SQL语句
while(rs.next()){ //循环遍历结果集
String[] s=new String[3];
for(int i=0;i<s.length;i++){
s[i]=rs.getString(i+1); //将得到的信息放入字符串数组
}
ll.add(s); //将字符串数据添加到列表
}
}catch(Exception e){
e.printStackTrace(); //捕获异常
}
finally{
try {rs.close();} catch (SQLException e) {e.printStackTrace();}
try {st.close();} catch (SQLException e) {e.printStackTrace();}
try {con.close();} catch (SQLException e) {e.printStackTrace();}
}
return ll;
}
////得到计量单位的最大编号
public static String getCUMaxNO(){
Connection con = getConnection();
Statement st = null;
ResultSet rs = null;
String str=new String();
try{
st=con.createStatement();
String sql="select max(unit_id) from countunit";
rs=st.executeQuery(sql);
rs.next();
if(rs.getString(1)==null){
str=String.valueOf(0);
}
else{
str=rs.getString(1);
}
}
catch(Exception e){
e.printStackTrace();
}finally{
try {rs.close();} catch (SQLException e) {e.printStackTrace();}
try {st.close();} catch (SQLException e) {e.printStackTrace();}
try {con.close();} catch (SQLException e) {e.printStackTrace();}
}
return str;
}
//更新计量单位
private static Object UPDATECOUNTUNIT=new Object();
public static String updateCU(String[] getmsg){
synchronized(UPDATECOUNTUNIT){ //方法加锁
Connection con = getConnection();
Statement st = null;
String idnum[]=getCountUnitID();
try{
int i;
st = con.createStatement();
for( i=0;i<idnum.length;i++){ //若是已有的计量单位,就更改
if(getmsg[1].equals(idnum[i])){
String sql = "update countunit set unit_name= '"+getmsg[2]+"',unit_remark= '"+getmsg[3]+"' where unit_id="+getmsg[1];
st.executeUpdate(sql);
break;
}
}
if(i==idnum.length){ //若不是已有的,就插入
String sql="insert into countunit(unit_id,unit_name,unit_remark) values('"+getmsg[1]+"','"+getmsg[2]+"','"+getmsg[3]+"')";
st.executeUpdate(sql);
}
}catch(Exception e){
e.printStackTrace() ;
return null;
}finally{
try{st.close();}catch(Exception e) {e.printStackTrace();}
try{con.close();}catch(Exception e) {e.printStackTrace();}
}
return "ok";
}
}
//得到计量单位的编号
private static String[] getCountUnitID(){
Connection con = getConnection();
Statement st = null;
ResultSet rs = null;
int count=getCount("countunit");
String[] ll=new String[count];
try{
st=con.createStatement();
String sql="select unit_id from countunit";
rs=st.executeQuery(sql);
int k=0;
System.out.println(rs.getRow()); //打印编号
while(rs.next()){
System.out.println(rs.getString(1));
ll[k]=rs.getString(1);
System.out.println(ll[k]+"k="+k);
k++;
}
}catch(Exception e){
e.printStackTrace();
}
finally{
try {rs.close();} catch (SQLException e) {e.printStackTrace();}
try {st.close();} catch (SQLException e) {e.printStackTrace();}
try {con.close();} catch (SQLException e) {e.printStackTrace();}
}
return ll;
}
//删除计量单位信息
private static Object DELCOUNTUNIT=new Object();
public static String delCU(String id) {
synchronized(DELCOUNTUNIT){ //加锁
Connection con = getConnection();
Statement st = null;
try{
st = con.createStatement();
String sql = "update countunit set unit_delflg='"+1+"' where unit_id="+id;
st.executeUpdate(sql);
}catch(Exception e){
e.printStackTrace() ;
return null;
}finally{
try{st.close();}catch(Exception e) {e.printStackTrace();}
try{con.close();}catch(Exception e) {e.printStackTrace();}
}
return "ok";
}
}
//根据计量单位id得到名称
public static String getCUnameById(String string) {
Connection con = getConnection();
Statement st = null;
ResultSet rs = null;
String str = null;
try{
st = con.createStatement();
String task = "select unit_name from CountUnit where unit_id='"+string+"';";
rs = st.executeQuery(task);
rs.next();
str=rs.getString(1);
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
try {rs.close();} catch (SQLException e) {e.printStackTrace();}
try {st.close();} catch (SQLException e) {e.printStackTrace();}
try {con.close();} catch (SQLException e) {e.printStackTrace();}
}
return str;
}
//根据员工id得到名称
public static String getWorkernameById(String string){
Connection con = getConnection();
Statement st = null;
ResultSet rs = null;
String str = null;
try{
st = con.createStatement();
String task = "select w_name from WorkerInfo where w_id='"+string+"';";
rs = st.executeQuery(task);
rs.next();
str=rs.getString(1);
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
try {rs.close();} catch (SQLException e) {e.printStackTrace();}
try {st.close();} catch (SQLException e) {e.printStackTrace();}
try {con.close();} catch (SQLException e) {e.printStackTrace();}
}
return str;
}
//根据计量单位名称得到id
public static String getCUidByname(String string) {
Connection con = getConnection();
Statement st = null;
ResultSet rs = null;
String str = null;
try{
st = con.createStatement();
Stri
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
点餐系统基于android (608个子文件)
resources.ap_ 722KB
Mainsurface.apk 801KB
jarlist.cache 119B
DBUtil.class 149KB
ServerAgentThread.class 22KB
MainUI.class 19KB
DataUtil.class 15KB
DBUtil.class 11KB
SelectVegeActivity.class 9KB
MyConverter.class 7KB
MyConverter.class 7KB
TypeExchangeUtil.class 7KB
MyConverter.class 7KB
UpdatePoint.class 7KB
VegeImageGrid.class 6KB
AddPoint.class 6KB
AccountOrder.class 6KB
MainUI$MainUIListener.class 6KB
TableInfoGrid.class 6KB
AddWorkerInfo.class 6KB
ListViewBar.class 6KB
VegeInfo.class 6KB
OrderManageActivity.class 6KB
AddVegeUI$addVege.class 6KB
EditWorkerInfo.class 6KB
UpdateVege.class 6KB
Constant.class 6KB
SelectTableActivity.class 6KB
DataUtil$4.class 5KB
Constant.class 5KB
DataUtil$10.class 5KB
DataUtil$2.class 5KB
PicUtil.class 5KB
SelectTableActivity$MyExpandableListAdapter.class 4KB
R$id.class 4KB
UpdateVegeImage.class 4KB
SelectVegeActivity$MyExpandableListView.class 4KB
OpenTableActivity.class 4KB
CateGoryUI$addCateGory.class 4KB
UpdateVegeImage$2.class 4KB
OrderManageActivity$1.class 4KB
SelectTableActivity$2.class 4KB
ResetUIActivity.class 4KB
AddMainImage.class 4KB
GetConfirmOrder.class 4KB
VegeImageUIActivity$2.class 4KB
ShowOrderActivity.class 4KB
TypeExchangeUtil.class 4KB
SocketClient.class 4KB
MainUI$DelButtonListener.class 4KB
R$drawable.class 4KB
AddWorkerInfo$3.class 4KB
MainUI$UpdateButtonListener.class 4KB
EditWorkerInfo$3.class 4KB
AccountOrder$2.class 4KB
PicScaleUtil.class 4KB
MainActivity.class 4KB
MainUI$AddButtonListener.class 4KB
AddChildImage$2.class 4KB
IOUtil.class 4KB
MainCateGoryUI$addMainCateGory.class 4KB
VegeIntroMsgUtil2.class 3KB
AddVegeUI$addVege$1.class 3KB
Constant.class 3KB
DataUtil$8.class 3KB
CateGoryUI$addCateGory$1.class 3KB
UpdateVege$1.class 3KB
AddMainImage$2.class 3KB
OrderManageActivity$MyOrderManageAdapter.class 3KB
VegeImageList.class 3KB
OpenTableActivity$1.class 3KB
ResetErrorActivity$1.class 3KB
UpdateImageGrid.class 3KB
VegeActivity.class 3KB
MainActivity$2.class 3KB
AddChildImage.class 3KB
TypeExchangeUtil.class 3KB
OpenTableActivity$3.class 3KB
PicManagerUtil.class 3KB
MainCateGoryUI$addMainCateGory$1.class 3KB
DataUtil$5.class 3KB
MainUI$4.class 3KB
LoginActivity.class 3KB
LoginActivity$1.class 3KB
InPutNumber.class 3KB
SelectTableActivity$MyExpandableListAdapter$1.class 3KB
VegeImageUIActivity.class 3KB
AddMainImage$1.class 3KB
ButtonListBar.class 3KB
LogoutActivity.class 3KB
SelectVegeActivity$MyExpandableListView$1.class 3KB
ShowOrderActivity$1.class 2KB
WorkerInfoTransform.class 2KB
DataUtil$3.class 2KB
DataUtil$6.class 2KB
DataGetUtilSimple.class 2KB
InPutNumber$1.class 2KB
ProgressBarActivity$1.class 2KB
DataUtil$7.class 2KB
LogoutActivity$4.class 2KB
共 608 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
weixin_43882700
- 粉丝: 3
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功