java编程思想 bian cheng wen ti

yi zhong xin de bian cheng si lu ( xia ): fu ntDB.java - 王朝网络手机版 - 欢迎访问王朝网络手机版m.yi zhong xin de bian cheng si lu ( xia ): fu ntDB.java&&  ntDB.java  --------------------------------------------------------------------------    /* cun qu shu ju ku 2002 zhu yi : he dba.ntDB bu neng hu huan qu dai , you qi zhu yi */  /*  fang fa jie shao :   public static String sql_TRANS_ERROR   public int rowC   public int colC   public String[] fieldN   public int[] fieldT   public int[] columnDisplayS   public String[][] data =  public boolean isSaveField( String s )  public String noPrefixField( String s ) guo zeng jia , hui fan hui zeng jia hou de id hao   public String toDB( Hashtable requestHt ) throws Exception  public Hashtable copyRequestHt( Hashtable requestHt ) throws Exception  public void createTable( String dbName  
, String globalTableName ) throws Exception  public int executeQuery( String _connName, String SQL )  
throws SQLException,Exception  public int executeUpdate( String _connName, String SQL )   
throws Exception  public String data(int i, String _fieldName){   public String data( int i  
, String _fieldName  
, int _begin   
, int _end )   cong shu ju ku zhong qu zhi
  public String getKV( String dbName , String tableName,int _pid , String _k )   
throws Exception  public String getKV( String dbName  
,String tableName  
,String _k  
,int _begin //  
) throws Exception  public String getKV( String dbName, String tableName,String _pid , String _k )   
throws Exception  public String getKV( String dbName  
,String tableName  
,String _pid  
,String _k  
,int _begin //  
) throws Exception   cong data zhong qu de zhi
  public String getKV( int _pid , String _k ) throws Exception   public String getKV( int
,String _k
,int _begin   
) throws Exception  public String getPublish( int _pid , String _k ) throws Exception{  public static boolean isNumeric( String s ){  public static boolean isInt( String s ){  public static boolean isDate( String s ){  public static boolean isDateTime( String s ){   public static String ntSubString( String _s , int _begin , int _end ){
  public static String nt8859( String s ) throws Exception{  public static String ntFormatHour( String s ){  public static int ntGetMonthDayCount( int year ,int month ){  public static String ntEncodeHtml( String s ){  public static String ntEncodeSimple( String s ){  public static String ntEncodeDB( String s ){
  public static String ntRemoveChar( String s, char cDel ){  public static int ntStringIndexOf( String[] ss , String s )  public static String toPinYin(String str, String flag) throws Exception {  public static String toPinYin_IntToPY(Integer n){
  public static void fileCopy(String from, String to, boolean overwrite) throws Exception{
  */  /* tiao yong fan li   * nttest  * &%@page import="java.util.*"%&  * &%@page import="java.text.*"%&  * &%@page import="dba.ntDB"%&  * &%  *
ntDB nt = new ntDB();  *
nt.executeQuery("yw","select * from msgboard_wjm");  *   * out.println( (new SimpleDateFormat(  *
"yyyy-MM-dd HH:mm:ss.SSS")).format(new Date()) );  *
( (new Date()).toString() );  *   *
out.println("&br&");  *
out.println( nt.rowCount );  *
out.println("&table border=1 &");  *
for(int i=0;i& nt.rowCi++ ){  *   *   *
if(i==0){  *
out.println("&tr&");  *
for(int k=0;k& nt.colCk++ ){  *
out.println("&td&");  *
out.print( nt.fieldName[k] );  *
out.print("&/td&");  *
out.println("&/tr&");  *
}  *   *
out.println("&tr&");  *
for(int j=0;j& nt.colCj++ ){  *
out.println("&td&");  *
out.println( nt.data[i][j] );  *
out.println("&/td&");  *
out.println("&/tr&");  *
out.println("&/table&");  * %&  */  import java.util.*;  import java.lang.*;  import java.text.*;  import java.sql.*;  import java.sql.C  import javax.sql.*;  import javax.naming.*;  import javax.transaction.*;  import java.io.*;  import java.net.*;  public class ntDB {  private C  private String connN  private S  private ResultSet rs =  private ResultSetMetaD  public static String sql_TRANS_ERROR =    " if @@error&&0 set @ntE=@ntE+1 \n"; wai fang fa , han zi zhuan hua wei pin yin   private static Hashtable ht_PinYin=new Hashtable(10);  public int rowC  public int colC  public String[] fieldN  public int[] fieldT  public int[] columnDisplayS  public String[][] data =  //// e wai fang fa   public ntDB() {   rowCount=-1;   colCount=-1;  }  private void getConn(){  
Context env=(Context)new InitialContext().lookup("java:comp/env");  
DataSource ds = (DataSource) env.lookup("jdbc/"+connName);  
con = ds.getConnection();  
}catch(Exception e){  
e.printStackTrace();  
}  }  private void closeConn() throws Exception  {   if( con != null )  
con.close();  }  // GBDP ji shu begin --------------------------------------  public boolean isSaveField( String s )  {   if( s.equals("edit")   
|| s.equals("add")   
|| s.equals("delete")   
|| s.equals("id")   
|| s.equals("globalTableName")   
|| s.equals("parentKey")   
|| s.equals("parentValue")   
|| s.equals("sql_trans")   
|| s.equals("dbName")   
|| s.toLowerCase().indexOf("submit") == 0   
|| s.toLowerCase().indexOf("nouse") == 0   
|| s.toLowerCase().indexOf("useless") == 0   
|| s.toLowerCase().indexOf("imagefield") == 0   
)     else     }  public String noPrefixField( String s )  {   if( s.toLowerCase().indexOf("numeric") == 0 )  
return s.substring(7,s.length());   else if( s.toLowerCase().indexOf("text") == 0 )  
return s.substring(4,s.length());   else if( s.toLowerCase().indexOf("datetime") == 0 )  
return s.substring(8,s.length());   else if( s.toLowerCase().indexOf("date") == 0   
&& s.toLowerCase().indexOf("datetime") & 0)  
return s.substring(4,s.length());   else if( s.toLowerCase().indexOf("int") == 0 )  
return s.substring(3,s.length());     }  public String toDB( Hashtable requestHt ) throws Exception  {   String result = "";    String sql = "";    String globalTableName =   int id = 0 ;   String sql_trans =   String dbName =   int masterId = 0;   String parentKey =   String parentValue =   // begin jian cha    if( requestHt.get("id")==null && requestHt.get("edit")!=null )   
throw new Exception("GBDP: bian ji mei you ti gong id hao ! ");   if( requestHt.get("id")==null && requestHt.get("delete")!=null )   
throw new Exception("GBDP: shan chu mei you ti gong id hao ! ");   globalTableName = (String)requestHt.get("globalTableName");   if( globalTableName == null || globalTableName.equals("") )  
throw new Exception("GBDP: mei you ti gong globalTableName! ");   if( requestHt.get("edit")!=null   
|| requestHt.get("delete")!=null )   {
id = Integer.parseInt((String)requestHt.get("id"));  
}catch(Exception e){  
throw new Exception("GBDP: mei you ti gong zheng que de id hao ! "+  
(String)requestHt.get("id"));  
}   }    sql_trans = (String)requestHt.get("sql_trans");   // yin wei bu shi bi xu , suo yi bu yong jian cha , yong dao shi zai jian cha   
   dbName = (String)requestHt.get("dbName");   if( dbName == null || dbName.equals("") )  
throw new Exception("GBDP: mei you ti gong dbName! ");  
cong biao jie gou de zhu biao id   try{  
masterId = Integer.parseInt((String)requestHt.get("masterId"));   }catch(Exception e){  
masterId = 0 ;    }  
   if( requestHt.get("add")!=null   
&& requestHt.get("parentKey")==null   
throw new Exception("GBDP: zeng jia mei you ti gong parentKey! ");    parentKey = (String)requestHt.get("parentKey");       if( requestHt.get("add")!=null   
&& requestHt.get("parentValue")==null   
throw new Exception("GBDP: zeng jia mei you ti gong parentValue! ");    parentValue = (String)requestHt.get("parentValue");       // end jian cha
      createTable( dbName , globalTableName );     
gai    if( requestHt.get("edit")!=null   
&& requestHt.get("delete")==null ) // isEdit && hasId   {  
cha shi fou cun zai   
executeQuery(dbName,  
"select * from "+ globalTableName +"_main "+  
" where id = "+id );  
if( rowCount &= 0 )  
throw new Exception( " xiu gai "+ globalTableName +  
" chu cuo : shu ju ku mei you zhao dao ci id hao '"+ id +"'");  
sql = ""+  
" declare @i
int \n"+  
" declare @ntE int \n"+  
" select @ntE=0
" begin tran
ru e wai xu yao zai shi wu nei zhi xing de yu ju , gong you 3 chu jia ru , add, edit , delete  
sql_TRANS_ERROR = " if @@error&&0 set @ntE=@ntE+1 \n";  
sql_trans = "" ;
lai cha ru hou mian de bao cun dao shu ju ku de sql yu ju zhong , shi qi zhong zai shi wu zhi zhong jian   
if( sql_trans != null && !sql_trans.equals("") )  
sql = sql + sql_trans + sql_TRANS_ERROR;   
Enumeration er37 = requestHt.keys();  
while (er37.hasMoreElements()) {  
String s = ((String)er37.nextElement()).trim();  
String sValue = ((String)requestHt.get(s)).trim();  
if( sValue == null )  
sValue = "";  
sValue = ntEncodeDB( sValue );  
String sTableName = globalTableN  
if( s.indexOf("numeric") == 0 || s.indexOf("n_") == 0 )  
{ sTableName = globalTableName + "_numeric" ; }  
else if( s.indexOf("int") == 0 || s.indexOf("i_") == 0 )  
{ sTableName = globalTableName + "_int" ; }  
else if( s.indexOf("date") == 0 || s.indexOf("d_") == 0 )  
{ sTableName = globalTableName + "_datetime";   
sValue = "'"+sValue+"'";   
else if( s.indexOf("text") == 0 || s.indexOf("t_") == 0)  
{ sTableName = globalTableName + "_text" ;   
sValue = "'"+sValue+"'";   
sValue = "'"+sValue+"'";   
xu fang zai zhe li , yin wei zhi you xiu gai he zeng jia shu zhi xing zi duan cai man zu sValue.equals("")  
if( sValue.equals("") )    
if( isSaveField(s) )  
sql = sql +  
" if exists ( select * from "+ sTableName +" where pid= "+ id +" and k='"+ noPrefixField(s) +"'" +" ) \n"+  
update "+ sTableName +" set v = "+ sValue +" \n"+  
where pid= "+ id +" and k='"+ noPrefixField(s) +"' \n" +  
if @@error&&0 set @ntE=@ntE+1 \n"+  
begin \n"+  
select @i=@i "+  
if( !sValue.equals("") && !sValue.equals("''") )   
sql = sql +  
select @i = ( select isNull(min(id),0)-1 from "+ sTableName +" ) \n"+  
if @i &= 0 select @i = -1 \n"+  
insert into "+ sTableName +" (id,pid,k,v)
values( @i, "+ id + " \n"+  
, '"+ noPrefixField(s) +"', "+ sValue +") \n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
sql = sql +  
" if @@error&&0 set @ntE=@ntE+1 \n"+  
}//end while  
sql = sql +  
" if @ntE = 0
commit tran
rollback tran
raiserror (' shu ju ku zhi xing chu cuo ! ',16,1) \n"+  
executeUpdate( dbName,sql );   } // end if edit  
jia bao cun ru shu ju ku    if( requestHt.get("add")!=null   
&& requestHt.get("edit")==null   
&& requestHt.get("delete")==null )   { // ge li ju bu bian liang   
rowNo = -9999;  
formNo = -9999;  
(dbName,"select isNull(max(id),0)+1 from "+ globalTableName +"");  
= Integer.parseInt( nt.data[0][0] );  
(dbName,"select isNull(min(id),0)-1 from "+ globalTableName +"");  
= Integer.parseInt( nt.data[0][0] );  
sql = ""+  
" declare @ntE int \n"+  
" declare @i
int \n"+  
" declare @formNo int \n"+  
" select @ntE=0
" begin tran
ru e wai xu yao zai shi wu nei zhi xing de yu ju , gong you 3 chu jia ru , add, edit , delete  
sql_TRANS_ERROR = " if @@error&&0 set @ntE=@ntE+1 \n";  
sql_trans = "" ;
lai cha ru hou mian de bao cun dao shu ju ku de sql yu ju zhong , shi qi zhong zai shi wu zhi zhong jian   
if( sql_trans != null && !sql_trans.equals("") )  
sql = sql + sql_trans + sql_TRANS_ERROR;   
sql = sql +  
" select @i = ( select isNull(max(id),0)+1 from "+ globalTableName +"_main ) \n"+  
" select @formNo = @i \n"+  
" insert into "+ globalTableName +"_main (id,pid,k,v) \n"+  
values( @i, "+ masterId +", '"+ parentKey +"', '"+ parentValue +"') \n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
Enumeration er44 = requestHt.keys();  
while (er44.hasMoreElements()) {  
String s = ((String)er44.nextElement()).trim();  
String sValue = ((String)requestHt.get(s));  
if( sValue == null )  
sValue = "";  
sValue = sValue.trim();  
if( sValue.equals("") )    
sValue = ntEncodeDB( sValue );  
String sTableName = globalTableN  
duan cha ru na ge lei xing (text,numeric,datetime...) de biao   
if( s.indexOf("numeric") == 0 || s.indexOf("n_") == 0 )  
{ sTableName = globalTableName + "_numeric" ; }  
else if( s.indexOf("int") == 0 || s.indexOf("i_") == 0 )  
{ sTableName = globalTableName + "_int" ; }  
else if( s.indexOf("date") == 0 || s.indexOf("d_") == 0 )  
{ sTableName = globalTableName + "_datetime";   
sValue = "'"+sValue+"'";   
else if( s.indexOf("text") == 0 || s.indexOf("t_") == 0 )  
{ sTableName = globalTableName + "_text"   
sValue = "'"+sValue+"'";   
sValue = "'"+sValue+"'";   
if( isSaveField(s) )   
yi : bao cun dao shu ju ku de shi hou jiang "numeric","date" deng qian zhui qu chu le
sql = sql +  
" select @i = ( select isNull(min(id),0)-1 from "+ sTableName +" ) \n"+  
" if @i &= 0 select @i = -1 \n"+  
" insert into "+ sTableName +" (id,pid,k,v) "+  
" values( @i, @formNo , '"+ noPrefixField(s) +"', "+ sValue +") "+  
if @@error&&0 set @ntE=@ntE+1 "+  
}//end while  
sql = sql +  
" if @ntE = 0
commit tran
rollback tran
raiserror (' shu ju ku zhi xing chu cuo !',16,1) "+  
executeQuery( dbName,sql + " select @formNo as id " );  
if( rowCount & 0 )  
result = data[0][0] ;   } // zeng jia    // jiang pid wei id de shan chu    if( requestHt.get("delete")!=null )
wei yi ban dou shi edit he delete tong shi cun zai    {   
cha pid shi fou cun zai   
executeQuery(dbName,  
"select * from "+ globalTableName +"_main "+  
" where id = "+id );  
if( rowCount &= 0 )  
throw new Exception(" shan chu "+ globalTableName +  
" chu cuo : mei you zhao dao ci id hao '"+ id +"'");  
sql = ""+  
" declare @ntE int \n"+  
" declare @i
int \n"+  
" select @ntE=0
" begin tran
ru e wai xu yao zai shi wu nei zhi xing de yu ju , gong you 3 chu jia ru , add, edit , delete  
sql_TRANS_ERROR = " if @@error&&0 set @ntE=@ntE+1 \n";  
sql_trans = "" ;
lai cha ru hou mian de bao cun dao shu ju ku de sql yu ju zhong , shi qi zhong zai shi wu zhi zhong jian   
if( sql_trans != null && !sql_trans.equals("") )  
sql = sql + sql_trans + sql_TRANS_ERROR;   
sql = sql +   
delete from "+ globalTableName +" where pid = "+ id + "\n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
delete from "+ globalTableName +"_numeric where pid = "+ id + "\n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
delete from "+ globalTableName +"_int where pid = "+ id + "\n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
delete from "+ globalTableName +"_datetime where pid = "+ id + "\n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
delete from "+ globalTableName +"_text where pid = "+ id + "\n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
delete from "+ globalTableName +"_main where id = "+ id + "\n"+  
if @@error&&0 set @ntE=@ntE+1 \n"+  
" if @ntE = 0
commit tran
rollback tran
raiserror (' shu ju ku zhi xing chu cuo ! ',16,1) \n"+  
executeUpdate(dbName, sql );   } // end shan chu     } // end toDB  public Hashtable copyRequestHt( Hashtable requestHt ) throws Exception  {   if( requestHt == null )      Hashtable ht = new Hashtable();   //   Enumeration e = requestHt.keys();   while (e.hasMoreElements()) {  
String s = ((String)e.nextElement());  
String sValue = ((String)requestHt.get(s));  
ht.put( s , sValue );   } // end while    //    }  public void createTable( String dbName  
, String globalTableName ) throws Exception  {   String sql = "";  
cha biao shi fou cun zai , ru guo mei you , jian 6 biao ,    //
t_main , t , t_numeric , t_datetime , t_text , t_int   for(int i=0;i&6;i++){  
String sTableName = globalTableN   
String sType = "varchar(255)";
if( i==1 )  
{ sTableName = globalTableName + "_numeric" ; sType = "numeric(38,8)" ;}  
else if( i==2 )  
{ sTableName = globalTableName + "_datetime"; sType = "datetime"; }  
else if( i==3 )  
{ sTableName = globalTableName + "_text" sType = "text"; }  
else if( i==4 )  
{ sTableName = globalTableName + "_main" }  
else if( i==5 )  
{ sTableName = globalTableName + "_int" sType = "int"; }  
sql = sql +  
" if not exists( select name from sysobjects
where name ='"+ sTableName +"' and type='U' ) \n"+  
create table "+ sTableName +"(
primary key \n"+   
"+ sType +" not null
varchar(255) not null
" end \n"+  
" if not exists( select name from sysindexes \n"+  
where name like '%idx_"+ sTableName +"_pid%' ) \n"+  
create index idx_"+sTableName+"_pid on "+sTableName+"(pid) \n"+  
" end \n"+  
" if not exists( select name from sysindexes \n"+  
where name like '%idx_"+ sTableName +"_k%' ) \n"+  
create index idx_"+sTableName+"_k on "+sTableName+"(k)
" end \n"+  
wei text zi duan bu neng jian li suo yin   
if( !sType.equals("text") ){  
sql = sql +  
" if not exists( select name from sysindexes \n"+  
where name like '%idx_"+ sTableName +"_v%' ) \n"+  
create index idx_"+sTableName+"_v on "+sTableName+"(v)
" end \n"+  
sql = sql + "";   } // end for create table    executeUpdate(dbName,sql);   } // end createTable()  // GBDP ji shu end -------------------------------------------  public int executeQuery( String _connName, String SQL )  
throws SQLException,Exception  {  
ht = new Hashtable();  
connName = _connN  
getConn();  
statement = con.createStatement();  
String sql = SQL ;  
= new String(sql.getBytes("GBK"),"8859_1");  
rs = statement.executeQuery( sql );  
}catch(Exception e){  
throw new Exception( e.getMessage() + "\n" + sql );  
if( rs == null )  
return -1 ;  
// getMetaData  
rsmd = rs.getMetaData();   
colCount = -1;  
colCount = rsmd.getColumnCount();  
fieldName = new String[colCount]; []  
fieldType = new int[colCount]; []  
columnDisplaySize = new int[colCount]; []  
for(int i=0;i&colCi++)  
fieldName[i] = rsmd.getColumnName(i+1) ;  
columnDisplaySize[i] = rsmd.getColumnDisplaySize(i+1) ;  
fieldType[i] = rsmd.getColumnType(i+1) ;  
if( colCount &= 0 )  
return -1 ;  
Vector v = new Vector();  
while( rs.next() )  
String[] sRow = new String[colCount];  
for(int i=0;i&colCi++){  
sRow[i] = rs.getString(i+1);  
if( fieldType[i] == java.sql.Types.DATE  
fieldType[i] == java.sql.Types.TIME  
fieldType[i] == java.sql.Types.TIMESTAMP  
sRow[i] = (new SimpleDateFormat(  
"yyyy-MM-dd HH:mm:ss.SSS")).format(rs.getTimestamp(i+1));  
v.add( sRow );  
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")).format(new Date())  
// java.sql.Types.DATE  
rowCount = -1;   
rowCount = v.size();   
data = new String[rowCount][colCount];  
for(int i=0;i&rowCi++)  
for(int j=0;j&colCj++){  
data[i][j] = ((String[])v.elementAt(i))[j];  
if( data[i][j] == null )  
data[i][j] = "";  
data[i][j] = data[i][j].trim();  
rs.close();  
statement.close();  
if( colCount &= 0 ){  
ht.put("fieldCount",""+colCount);  
ht.put("colCount",""+colCount);  
if( fieldName != null )  
ht.put("fieldName",fieldName);  
if( fieldType != null )  
ht.put("fieldType",fieldType);  
if( data != null )  
ht.put("data",data);  
ht.put("rowCount",""+rowCount);  
}finally{  
closeConn();  
return rowC  } // end executeQuery() hui shou ying xiang de ji lu shu liang   public int executeUpdate( String _connName, String SQL )   
throws Exception  {  
String sql = SQL ;  
= new String(sql.getBytes("GBK"),"8859_1");    
connName = _connN  
getConn();  
statement = con.createStatement();   
result = statement.executeUpdate( sql );  
catch (Exception e33)  
throw new Exception( "newtower:ntDB:executeUpdate:"+ e33.getMessage() + "\n" + sql );  
finally{  
closeConn();  
}    }  public String data(int i, String _fieldName){  
if( i & rowCount-1 )  
return "";  
if( ntStringIndexOf(fieldName,_fieldName) & 0 )   
return "";  
return data[i][ntStringIndexOf(fieldName,_fieldName)];  }  public String data( int i  
, String _fieldName  
, int _begin   
, int _end )  {  
String s = data(i,_fieldName);  
s = ntSubString( s , _begin , _end );    }  public String getKV( String dbName, String tableName,String _pid , String _k )   
throws Exception  {   if( _pid == null || _pid.equals("") )   
return "";   return getKV( dbName ,tableName , Integer.parseInt(_pid),_k );   }   public String getKV( String dbName, String tableName,int _pid , String _k )   
throws Exception  {  
String tableNameSuffix = "";  
yin wei text,int deng qian zhui bu zai bao cun dao shu ju ku , suo yi bu bi yi xia de dai ma le   
if( _k.indexOf("numeric")==0 && tableName.indexOf("_numeric")&0 )  
tableNameSuffix = "_numeric";  
else if( _k.indexOf("int")==0 && tableName.indexOf("_int")&0 )  
tableNameSuffix = "_int";  
else if( _k.indexOf("text")==0 && tableName.indexOf("_text")&0 )  
tableNameSuffix = "_text";  
else if( _k.indexOf("date")==0 && tableName.indexOf("_datetime")&0 )  
tableNameSuffix = "_datetime";  
this.executeQuery(dbName,  
" select v from "+ tableName + tableNameSuffix +  
" where pid = " + _pid +  
and k ='"+ (_k) + "'" +  
if( this.rowCount & 1 )  
throw new Exception( tableName + tableNameSuffix +  
" fa xian duo yu yi ge zhi pid=["+ _pid +"] k=[" + _k +"]" );  
if( this.rowCount ==1 )  
return data[0][0];  
return "";  }  public String getKV( String dbName  
,String tableName  
,String _pid  
,String _k  
,int _begin //  
) throws Exception  {   if( _pid == null || _pid.equals("") )   
return "";   return getKV( dbName,  
tableName,  
Integer.parseInt(_pid),  
_begin,  
_end);   }   public String getKV( String dbName  
,String tableName  
,String _k  
,int _begin //  
) throws Exception  {     
String s = getKV( dbName ,tableName, _pid , _k );  
s = ntSubString( s , _begin , _end );    }  public String getKV( int _pid , String _k ) throws Exception  {  
String s = "";  
for(int i=0;i&rowCi++)  
if( data(i,"pid").equals(""+_pid)  
&& data(i,"k").equals(""+_k)  
{ s = data(i,"v") ; }  
}    }  public String getKV( int
,String _k
,int _begin   
) throws Exception  {  
String s = getKV( _pid , _k );  
s = ntSubString( s , _begin , _end );    }  public String getPublish( int _pid , String _k ) throws Exception{  
return getKV( "eweb","publish" , _pid, _k );  }  //////////////////////////////////////////////////////////   public static boolean isNumeric( String s ){  
Double.parseDouble( s );  
}catch(Exception e){    
}     }   public static boolean isInt( String s ){  
Integer.parseInt( s );  
}catch(Exception e){    
}     }   public static boolean isDate( String s ){  
java.util.D  
d = DateFormat.getDateInstance().parse( s );  
}catch(Exception e){     
}       }   public static boolean isDateTime( String s ){  
return isDate(s);   }      public static String ntSubString( String _s , int _begin , int _end ){  
String r = _  
r = _s.substring(_begin,_end);  
}catch(Exception e238SubString){  
}     }   public static String nt8859( String s ) throws Exception{  
return new String(s.getBytes("GBK"),"8859_1");   }   public static String ntFormatHour( String s ){  
if( s == null )    
String r =  
if( s.trim().length() == 1 )  
r = "0" +     }   public static int ntGetMonthDayCount( int year ,int month ){  
int r = 31 ;  
if( month == 4 || month == 6 || month == 9 || month == 11 )  
r = 30 ;  
if( month == 2 ){  
r = 28 ;  
if( (year%4)==0 && (year%400)==0 ) r = 29 ;  
if( (year%4)==0 && (year%100)!=0 ) r = 29 ;  
}     }   public static String ntEncodeHtml( String s ){  
if( s == null )    
String r = "";  
for( int i=0;i&s.length() ;i++ ){  
char c = s.charAt(i);  
if( c == '&' )  
r = r + "&" ;  
else if( c == '\"' )  
r = r + "&";  
else if( c == '&' )  
r = r + "&";  
else if( c == '&' )  
r = r + "&";  
else if( c == '\n' )  
r = r + "&BR&";  
else if( c == ' ' )  
r = r + "&";  
r = r +  
}//end for     } // end ntEncodeHtml  
lai jiang pu tong zi fu chuan zhuan hua dao "" zhi jian , li ru asdf"\ dao "asdf\"\\"   public static String ntEncodeSimple( String s ){  
if( s == null )    
String r = "";  
for( int i=0;i&s.length() ;i++ ){  
char c = s.charAt(i);  
if( c == '\n' )  
r = r + "" ;  
else if( c == '\\' )  
r = r + "\\\\";  
else if( c == (char)(13) )  
else if( c == (char)(10) )  
else if( c == '\"' )  
r = r + "\\\"";  
r = r +  
}     } // end ntEncodeSimple   public static String ntEncodeDB( String s ){  
if( s == null )    
String r = "";  
for( int i=0;i&s.length() ;i++ ){  
char c = s.charAt(i);  
if( c == '\'' )  
r = r + "''" ;  
r = r +  
}     } // end ntEncodeDB   public static String ntRemoveChar( String s, char cDel ){  
if( s == null )  
String r = "";  
for( int i=0;i&s.length() ;i++ ){  
char c = s.charAt(i);  
if( c == cDel ) ;  
else r = r +  
}     } // end ntRemoveChar   public static int ntStringIndexOf( String[] ss , String s )   {  
int pos = -1 ;  
for(int i=0;i&ss.i++)  
if( ss[i].equalsIgnoreCase(s) )  
pos =    
}     }      public static String toPinYin(String str, String flag) throws Exception {  
char[] hz= nt8859(str).toCharArray();  
int len=nt8859(str).length();  
int p,q;  
String ret="";  
for(int i=0;i&i++){  
p=(int)hz[i];  
if(p&160){  
q=(int)hz[++i];  
p=p*256+q-65536;  
if( flag.length()&0 )  
if( flag.indexOf("C")==0 ){  
String s = toPinYin_IntToPY(new Integer(p));  
s = s.substring(0,1).toUpperCase() +   
s.substring(1,s.length());  
ret+= s + flag.substring(1,flag.length()) ;  
ret+= toPinYin_IntToPY(new Integer(p)) +   
ret+= toPinYin_IntToPY(new Integer(p)) ;  
if( flag.indexOf("C")==0 )  
return ret.substring(0,ret.length()-flag.length()+1);  
return ret.substring(0,ret.length()-flag.length());    }   public static String toPinYin_IntToPY(Integer n){  
int num=n.intValue();  
if(num&0&&num&160){  
return String.valueOf((char)num);  
else if(num&-20319||num&-10247){  
return "";  
if(ht_PinYin.size()==0){toPinYin_ht();}  
while(!ht_PinYin.containsKey(Integer.toString(num)))num--;  
return ht_PinYin.get(Integer.toString(num)).toString();  
}   }   private static void toPinYin_ht(){  
ht_PinYin.put("-20319","a");  
ht_PinYin.put("-20317","ai");  
ht_PinYin.put("-20304","an");  
ht_PinYin.put("-20295","ang");  
ht_PinYin.put("-20292","ao");  
ht_PinYin.put("-20283","ba");  
ht_PinYin.put("-20265","bai");  
ht_PinYin.put("-20257","ban");  
ht_PinYin.put("-20242","bang");  
ht_PinYin.put("-20230","bao");  
ht_PinYin.put("-20051","bei");  
ht_PinYin.put("-20036","ben");  
ht_PinYin.put("-20032","beng");  
ht_PinYin.put("-20026","bi");  
ht_PinYin.put("-20002","bian");  
ht_PinYin.put("-19990","biao");  
ht_PinYin.put("-19986","bie");  
ht_PinYin.put("-19982","bin");  
ht_PinYin.put("-19976","bing");  
ht_PinYin.put("-19805","bo");  
ht_PinYin.put("-19784","bu");  
ht_PinYin.put("-19775","ca");  ht_PinYin.put("-19774","cai");  ht_PinYin.put("-19763","can");  ht_PinYin.put("-19756","cang");  ht_PinYin.put("-19751","cao");  ht_PinYin.put("-19746","ce");  ht_PinYin.put("-19741","ceng");  ht_PinYin.put("-19739","cha");  ht_PinYin.put("-19728","chai");  ht_PinYin.put("-19725","chan");  ht_PinYin.put("-19715","chang");  ht_PinYin.put("-19540","chao");  ht_PinYin.put("-19531","che");  ht_PinYin.put("-19525","chen");  ht_PinYin.put("-19515","cheng");  ht_PinYin.put("-19500","chi");  ht_PinYin.put("-19484","chong");  ht_PinYin.put("-19479","chou");  ht_PinYin.put("-19467","chu");  ht_PinYin.put("-19289","chuai");  ht_PinYin.put("-19288","chuan");  ht_PinYin.put("-19281","chuang");  ht_PinYin.put("-19275","chui");  ht_PinYin.put("-19270","chun");  ht_PinYin.put("-19263","chuo");  ht_PinYin.put("-19261","ci");  ht_PinYin.put("-19249","cong");  ht_PinYin.put("-19243","cou");  ht_PinYin.put("-19242","cu");  ht_PinYin.put("-19238","cuan");  ht_PinYin.put("-19235","cui");  ht_PinYin.put("-19227","cun");  ht_PinYin.put("-19224","cuo");  ht_PinYin.put("-19218","da");  ht_PinYin.put("-19212","dai");  ht_PinYin.put("-19038","dan");  ht_PinYin.put("-19023","dang");  ht_PinYin.put("-19018","dao");  ht_PinYin.put("-19006","de");  ht_PinYin.put("-19003","deng");  ht_PinYin.put("-18996","di");  ht_PinYin.put("-18977","dian");  ht_PinYin.put("-18961","diao");  ht_PinYin.put("-18952","die");  ht_PinYin.put("-18783","ding");  ht_PinYin.put("-18774","diu");  ht_PinYin.put("-18773","dong");  ht_PinYin.put("-18763","dou");  ht_PinYin.put("-18756","du");  ht_PinYin.put("-18741","duan");  ht_PinYin.put("-18735","dui");  ht_PinYin.put("-18731","dun");  ht_PinYin.put("-18722","duo");  ht_PinYin.put("-18710","e");  ht_PinYin.put("-18697","en");  ht_PinYin.put("-18696","er");  ht_PinYin.put("-18526","fa");  ht_PinYin.put("-18518","fan");  ht_PinYin.put("-18501","fang");  ht_PinYin.put("-18490","fei");  ht_PinYin.put("-18478","fen");  ht_PinYin.put("-18463","feng");  ht_PinYin.put("-18448","fo");  ht_PinYin.put("-18447","fou");  ht_PinYin.put("-18446","fu");  ht_PinYin.put("-18239","ga");  ht_PinYin.put("-18237","gai");  ht_PinYin.put("-18231","gan");  ht_PinYin.put("-18220","gang");  ht_PinYin.put("-18211","gao");  ht_PinYin.put("-18201","ge");  ht_PinYin.put("-18184","gei");  ht_PinYin.put("-18183","gen");  ht_PinYin.put("-18181","geng");  ht_PinYin.put("-18012","gong");  ht_PinYin.put("-17997","gou");  ht_PinYin.put("-17988","gu");  ht_PinYin.put("-17970","gua");  ht_PinYin.put("-17964","guai");  ht_PinYin.put("-17961","guan");  ht_PinYin.put("-17950","guang");  ht_PinYin.put("-17947","gui");  ht_PinYin.put("-17931","gun");  ht_PinYin.put("-17928","guo");  ht_PinYin.put("-17922","ha");  ht_PinYin.put("-17759","hai");  ht_PinYin.put("-17752","han");  ht_PinYin.put("-17733","hang");  ht_PinYin.put("-17730","hao");  ht_PinYin.put("-17721","he");  ht_PinYin.put("-17703","hei");  ht_PinYin.put("-17701","hen");  ht_PinYin.put("-17697","heng");  ht_PinYin.put("-17692","hong");  ht_PinYin.put("-17683","hou");  ht_PinYin.put("-17676","hu");  ht_PinYin.put("-17496","hua");  ht_PinYin.put("-17487","huai");  ht_PinYin.put("-17482","huan");  ht_PinYin.put("-17468","huang");  ht_PinYin.put("-17454","hui");  ht_PinYin.put("-17433","hun");  ht_PinYin.put("-17427","huo");  ht_PinYin.put("-17417","ji");  ht_PinYin.put("-17202","jia");  ht_PinYin.put("-17185","jian");  ht_PinYin.put("-16983","jiang");  ht_PinYin.put("-16970","jiao");  ht_PinYin.put("-16942","jie");  ht_PinYin.put("-16915","jin");  ht_PinYin.put("-16733","jing");  ht_PinYin.put("-16708","jiong");  ht_PinYin.put("-16706","jiu");  ht_PinYin.put("-16689","ju");  ht_PinYin.put("-16664","juan");  ht_PinYin.put("-16657","jue");  ht_PinYin.put("-16647","jun");  ht_PinYin.put("-16474","ka");  ht_PinYin.put("-16470","kai");  ht_PinYin.put("-16465","kan");  ht_PinYin.put("-16459","kang");  ht_PinYin.put("-16452","kao");  ht_PinYin.put("-16448","ke");  ht_PinYin.put("-16433","ken");  ht_PinYin.put("-16429","keng");  ht_PinYin.put("-16427","kong");  ht_PinYin.put("-16423","kou");  ht_PinYin.put("-16419","ku");  ht_PinYin.put("-16412","kua");  ht_PinYin.put("-16407","kuai");  ht_PinYin.put("-16403","kuan");  ht_PinYin.put("-16401","kuang");  ht_PinYin.put("-16393","kui");  ht_PinYin.put("-16220","kun");  ht_PinYin.put("-16216","kuo");  ht_PinYin.put("-16212","la");  ht_PinYin.put("-16205","lai");  ht_PinYin.put("-16202","lan");  ht_PinYin.put("-16187","lang");  ht_PinYin.put("-16180","lao");  ht_PinYin.put("-16171","le");  ht_PinYin.put("-16169","lei");  ht_PinYin.put("-16158","leng");  ht_PinYin.put("-16155","li");  ht_PinYin.put("-15959","lia");  ht_PinYin.put("-15958","lian");  ht_PinYin.put("-15944","liang");  ht_PinYin.put("-15933","liao");  ht_PinYin.put("-15920","lie");  ht_PinYin.put("-15915","lin");  ht_PinYin.put("-15903","ling");  ht_PinYin.put("-15889","liu");  ht_PinYin.put("-15878","long");  ht_PinYin.put("-15707","lou");  ht_PinYin.put("-15701","lu");  ht_PinYin.put("-15681","lv");  ht_PinYin.put("-15667","luan");  ht_PinYin.put("-15661","lue");  ht_PinYin.put("-15659","lun");  ht_PinYin.put("-15652","luo");  ht_PinYin.put("-15640","ma");  ht_PinYin.put("-15631","mai");  ht_PinYin.put("-15625","man");  ht_PinYin.put("-15454","mang");  ht_PinYin.put("-15448","mao");  ht_PinYin.put("-15436","me");  ht_PinYin.put("-15435","mei");  ht_PinYin.put("-15419","men");  ht_PinYin.put("-15416","meng");  ht_PinYin.put("-15408","mi");  ht_PinYin.put("-15394","mian");  ht_PinYin.put("-15385","miao");  ht_PinYin.put("-15377","mie");  ht_PinYin.put("-15375","min");  ht_PinYin.put("-15369","ming");  ht_PinYin.put("-15363","miu");  ht_PinYin.put("-15362","mo");  ht_PinYin.put("-15183","mou");  ht_PinYin.put("-15180","mu");  ht_PinYin.put("-15165","na");  ht_PinYin.put("-15158","nai");  ht_PinYin.put("-15153","nan");  ht_PinYin.put("-15150","nang");  ht_PinYin.put("-15149","nao");  ht_PinYin.put("-15144","ne");  ht_PinYin.put("-15143","nei");  ht_PinYin.put("-15141","nen");  ht_PinYin.put("-15140","neng");  ht_PinYin.put("-15139","ni");  ht_PinYin.put("-15128","nian");  ht_PinYin.put("-15121","niang");  ht_PinYin.put("-15119","niao");  ht_PinYin.put("-15117","nie");  ht_PinYin.put("-15110","nin");  ht_PinYin.put("-15109","ning");  ht_PinYin.put("-14941","niu");  ht_PinYin.put("-14937","nong");  ht_PinYin.put("-14933","nu");  ht_PinYin.put("-14930","nv");  ht_PinYin.put("-14929","nuan");  ht_PinYin.put("-14928","nue");  ht_PinYin.put("-14926","nuo");  ht_PinYin.put("-14922","o");  ht_PinYin.put("-14921","ou");  ht_PinYin.put("-14914","pa");  ht_PinYin.put("-14908","pai");  ht_PinYin.put("-14902","pan");  ht_PinYin.put("-14894","pang");  ht_PinYin.put("-14889","pao");  ht_PinYin.put("-14882","pei");  ht_PinYin.put("-14873","pen");  ht_PinYin.put("-14871","peng");  ht_PinYin.put("-14857","pi");  ht_PinYin.put("-14678","pian");  ht_PinYin.put("-14674","piao");  ht_PinYin.put("-14670","pie");  ht_PinYin.put("-14668","pin");  ht_PinYin.put("-14663","ping");  ht_PinYin.put("-14654","po");  ht_PinYin.put("-14645","pu");  ht_PinYin.put("-14630","qi");  ht_PinYin.put("-14594","qia");  ht_PinYin.put("-14429","qian");  ht_PinYin.put("-14407","qiang");  ht_PinYin.put("-14399","qiao");  ht_PinYin.put("-14384","qie");  ht_PinYin.put("-14379","qin");  ht_PinYin.put("-14368","qing");  ht_PinYin.put("-14355","qiong");  ht_PinYin.put("-14353","qiu");  ht_PinYin.put("-14345","qu");  ht_PinYin.put("-14170","quan");  ht_PinYin.put("-14159","que");  ht_PinYin.put("-14151","qun");  ht_PinYin.put("-14149","ran");  ht_PinYin.put("-14145","rang");  ht_PinYin.put("-14140","rao");  ht_PinYin.put("-14137","re");  ht_PinYin.put("-14135","ren");  ht_PinYin.put("-14125","reng");  ht_PinYin.put("-14123","ri");  ht_PinYin.put("-14122","rong");  ht_PinYin.put("-14112","rou");  ht_PinYin.put("-14109","ru");  ht_PinYin.put("-14099","ruan");  ht_PinYin.put("-14097","rui");  ht_PinYin.put("-14094","run");  ht_PinYin.put("-14092","ruo");  ht_PinYin.put("-14090","sa");  ht_PinYin.put("-14087","sai");  ht_PinYin.put("-14083","san");  ht_PinYin.put("-13917","sang");  ht_PinYin.put("-13914","sao");  ht_PinYin.put("-13910","se");  ht_PinYin.put("-13907","sen");  ht_PinYin.put("-13906","seng");  ht_PinYin.put("-13905","sha");  ht_PinYin.put("-13896","shai");  ht_PinYin.put("-13894","shan");  ht_PinYin.put("-13878","shang");  ht_PinYin.put("-13870","shao");  ht_PinYin.put("-13859","she");  ht_PinYin.put("-13847","shen");  ht_PinYin.put("-13831","sheng");  ht_PinYin.put("-13658","shi");  ht_PinYin.put("-13611","shou");  ht_PinYin.put("-13601","shu");  ht_PinYin.put("-13406","shua");  ht_PinYin.put("-13404","shuai");  ht_PinYin.put("-13400","shuan");  ht_PinYin.put("-13398","shuang");  ht_PinYin.put("-13395","shui");  ht_PinYin.put("-13391","shun");  ht_PinYin.put("-13387","shuo");  ht_PinYin.put("-13383","si");  ht_PinYin.put("-13367","song");  ht_PinYin.put("-13359","sou");  ht_PinYin.put("-13356","su");  ht_PinYin.put("-13343","suan");  ht_PinYin.put("-13340","sui");  ht_PinYin.put("-13329","sun");  ht_PinYin.put("-13326","suo");  ht_PinYin.put("-13318","ta");  ht_PinYin.put("-13147","tai");  ht_PinYin.put("-13138","tan");  ht_PinYin.put("-13120","tang");  ht_PinYin.put("-13107","tao");  ht_PinYin.put("-13096","te");  ht_PinYin.put("-13095","teng");  ht_PinYin.put("-13091","ti");  ht_PinYin.put("-13076","tian");  ht_PinYin.put("-13068","tiao");  ht_PinYin.put("-13063","tie");  ht_PinYin.put("-13060","ting");  ht_PinYin.put("-12888","tong");  ht_PinYin.put("-12875","tou");  ht_PinYin.put("-12871","tu");  ht_PinYin.put("-12860","tuan");  ht_PinYin.put("-12858","tui");  ht_PinYin.put("-12852","tun");  ht_PinYin.put("-12849","tuo");  ht_PinYin.put("-12838","wa");  ht_PinYin.put("-12831","wai");  ht_PinYin.put("-12829","wan");  ht_PinYin.put("-12812","wang");  ht_PinYin.put("-12802","wei");  ht_PinYin.put("-12607","wen");  ht_PinYin.put("-12597","weng");  ht_PinYin.put("-12594","wo");  ht_PinYin.put("-12585","wu");  ht_PinYin.put("-12556","xi");  ht_PinYin.put("-12359","xia");  ht_PinYin.put("-12346","xian");  ht_PinYin.put("-12320","xiang");  ht_PinYin.put("-12300","xiao");  ht_PinYin.put("-12120","xie");  ht_PinYin.put("-12099","xin");  ht_PinYin.put("-12089","xing");  ht_PinYin.put("-12074","xiong");  ht_PinYin.put("-12067","xiu");  ht_PinYin.put("-12058","xu");  ht_PinYin.put("-12039","xuan");  ht_PinYin.put("-11867","xue");  ht_PinYin.put("-11861","xun");  ht_PinYin.put("-11847","ya");  ht_PinYin.put("-11831","yan");  ht_PinYin.put("-11798","yang");  ht_PinYin.put("-11781","yao");  ht_PinYin.put("-11604","ye");  ht_PinYin.put("-11589","yi");  ht_PinYin.put("-11536","yin");  ht_PinYin.put("-11358","ying");  ht_PinYin.put("-11340","yo");  ht_PinYin.put("-11339","yong");  ht_PinYin.put("-11324","you");  ht_PinYin.put("-11303","yu");  ht_PinYin.put("-11097","yuan");  ht_PinYin.put("-11077","yue");  ht_PinYin.put("-11067","yun");  ht_PinYin.put("-11055","za");  ht_PinYin.put("-11052","zai");  ht_PinYin.put("-11045","zan");  ht_PinYin.put("-11041","zang");  ht_PinYin.put("-11038","zao");  ht_PinYin.put("-11024","ze");  ht_PinYin.put("-11020","zei");  ht_PinYin.put("-11019","zen");  ht_PinYin.put("-11018","zeng");   ht_PinYin.put("-11014","zha");   ht_PinYin.put("-10838","zhai");   ht_PinYin.put("-10832","zhan");   ht_PinYin.put("-10815","zhang");   ht_PinYin.put("-10800","zhao");   ht_PinYin.put("-10790","zhe");   ht_PinYin.put("-10780","zhen");   ht_PinYin.put("-10764","zheng");   ht_PinYin.put("-10587","zhi");   ht_PinYin.put("-10544","zhong");   ht_PinYin.put("-10533","zhou");   ht_PinYin.put("-10519","zhu");   ht_PinYin.put("-10331","zhua");   ht_PinYin.put("-10329","zhuai");   ht_PinYin.put("-10328","zhuan");   ht_PinYin.put("-10322","zhuang");   ht_PinYin.put("-10315","zhui");   ht_PinYin.put("-10309","zhun");   ht_PinYin.put("-10307","zhuo");   ht_PinYin.put("-10296","zi");   ht_PinYin.put("-10281","zong");   ht_PinYin.put("-10274","zou");   ht_PinYin.put("-10270","zu");   ht_PinYin.put("-10262","zuan");   ht_PinYin.put("-10260","zui");   ht_PinYin.put("-10256","zun");   ht_PinYin.put("-10254","zuo");   ht_PinYin.put("-10247","zz");  } jian 、 mu lu fu zhi   public static void fileCopy(String from, String to, boolean overwrite) throws Exception{  
File src = new File(from);  
File dest = new File(to);  
FileInputStream fis = new FileInputStream(src);  
FileOutputStream fos = new FileOutputStream(dest, !overwrite);  
byte[] buf = new byte[512];  
int size = fis.read(buf);  
while(size != -1) {  
fos.write(buf, 0, size);  
size = fis.read(buf);  
fis.close();   
fos.close();  
}catch (FileNotFoundException fnfe){  
if(src.isDirectory()) {  
/* yuan wen jian shi mu lu
fu zhi mu lu */  
File[] files = src.listFiles();  
Stack stack = new Stack();  
for(int i = 0; i & files. i++) {
dest.mkdirs();  
System.out.println( files[i ]. getName() );  
fileCopy(src + File.separator + files[ i].getName(), to + File.separator + files[ i].getName(), overwrite);  
}else{  
/* yuan wen jian bu cun zai huo qi ta yi chang qing kuang , pao chu yi chang */  
throw new Exception(" yuan wen jian bu cun zai huo qi ta yi chang qing kuang !");  
}catch (IOException e) {   
/* wei zhi de I/O yi chang */  
throw new Exception(" wei zhi de I/O yi chang !");  
}  } // end fileCopy()  //    } // end class【】【】(王朝网络手机版 m.)&&&电脑完整版: & &上一篇下一篇&&
&&2005-&&版權所有&&

我要回帖

更多关于 java经典编程300例 的文章

 

随机推荐