📄 dealstring.java
字号:
package Bean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import db.DBCon;
public class DealString {
public DealString() {}
/**
* 分隔字符串
* @param str 被分隔的串
* @param c 分隔符
* */
public String[] splitStr(String str,char c){
str+=c;
int n=0;
for(int i=0;i<str.length();i++){
if(str.charAt(i)==c) n++;
}
String out[]=new String[n];
for(int i=0;i<n;i++){
int index=str.indexOf(c);
out[i]=str.substring(0,index);
str=str.substring(index+1,str.length());
}
return out;
}
/**
* 得到当前时间
* */
public String getDataTime(){
java.text.SimpleDateFormat f=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=f.format(new java.util.Date());
return time;
}
/**
* 得到当前日期
* */
public String getShortTime(){
java.text.SimpleDateFormat f=new java.text.SimpleDateFormat("yyyy-MM-dd");
String time=f.format(new java.util.Date());
return time;
}
/**
* 判断是不是字符串是否可以转化为日期型
*
* */
public boolean isdatetime(String timestr){
try{
java.text.SimpleDateFormat f=new java.text.SimpleDateFormat("yyyy-MM-dd");
f.parse(timestr);
}
catch(Exception ex){return false;
}
return true;
}
/**
* 字符串转化为日期型
* */
public java.util.Date valueofDate(String timestr){
java.util.Date dateti=null;
try{
java.text.SimpleDateFormat f=new java.text.SimpleDateFormat("yyyy-MM-dd");
dateti=f.parse(timestr);
}catch(Exception ex){return null;
}
return dateti;
}
/**
* 得到两个日期的天数差
* */
public long getDaysInterval(java.util.Date d1,java.util.Date d2){
return (d2.getTime()-d1.getTime())/86400000;
}
/**
* 用日期取得唯一编号
* */
public String makeID(){
java.text.SimpleDateFormat f=new java.text.SimpleDateFormat("yyyyMMddHHmmssSS");
String time=f.format(new java.util.Date());
time+=(int)(Math.random()*1000);
return time;
}
/**
* 得到指定栏目的所用子栏目ID
*
* */
String menus="";
db.DBCon dc;
Connection con=null;
PreparedStatement preStmt;
public String[] MenuChild(String MenuID){
dc=new db.DBCon();
try {
con = DBCon.getInstance().getConnection("Devault");
preStmt =con.prepareStatement("select Id from menu where ParentID=? order by OrderList",
ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
} catch (SQLException e){e.printStackTrace();
}
menus=MenuID;
try{ChildMenu(MenuID);
}catch(Exception ex){System.out.print("在DealString中,得到指定栏目的所用子栏目ID出错,错误为:"+ex);
}finally{dc.freeConnection("Default", con);
}
String[] mennuIds=this.splitStr(menus, '|');
return mennuIds;
}
private void ChildMenu(String prentId){
//String sql="select Id from menu where ParentID="+prentId+" order by OrderList";
//PreparedStatement p_Stm=null;
//ResultSet r_rs=null;
ResultSet rs = null;
try{
preStmt.setString(1, prentId);
rs = preStmt.executeQuery();
while(rs.next()){
menus+="|"+rs.getString("Id");
ChildMenu(rs.getString("Id"));//用递归调用查找子菜单
}
}
catch(SQLException ex)
{
System.out.println("在查找子菜单的时候出错:"+ex);
}finally{
try{
rs.close();
preStmt.close();
}
catch(SQLException ex){
System.out.println("在查找子菜单关闭记录集时出错:"+ex);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -