ASF Bugzilla – Attachment 3309 Details for
Bug 12843
[PATCH] Make POI handle chinese better
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
mainFunctionJava
runer.java (text/java), 22.47 KB, created by
jubeson
on 2002-10-02 08:16:19 UTC
(
hide
)
Description:
mainFunctionJava
Filename:
MIME Type:
Creator:
jubeson
Created:
2002-10-02 08:16:19 UTC
Size:
22.47 KB
patch
obsolete
>package poitest; >import org.apache.poi.poifs.filesystem.POIFSFileSystem; >import org.apache.poi.hssf.usermodel.HSSFCell; >import org.apache.poi.hssf.usermodel.HSSFSheet; >import org.apache.poi.hssf.usermodel.HSSFWorkbook; >import org.apache.poi.hssf.usermodel.HSSFRow; >import java.util.*; >import java.sql.SQLException; >import java.sql.Connection; >import java.sql.DatabaseMetaData; >import java.sql.DriverManager; >import java.sql.*; >import java.io.*; >import java.text.SimpleDateFormat; > > > >import java.text.NumberFormat; >/** > * Title: > * Description: > * Copyright: Copyright (c) 2001 > * Company: > * @author > * @version 1.0 > */ > >public class runer { > > public runer() { > } > public static void main(String[] args) { > Connection conn ; > try{ > //String tmp = args[0]; > //String tmp = "/usr/local/JRun-31/servers/default/resource-app/Resources/Network/91\u7DB2\u8DEF\u5BB9\u91CF\u53CA\u4F7F\u7528\u73FE\u6CC1\u9031\u8868.xls"; > //System.out.println("%%%%%%%%%%%%%%%% "+args[0]); > PreparedStatement ps = null; > HSSFRow row = null; > HSSFCell cell = null; > ResultSet rs= null; > //String tmp = "f:/temp/91\u7DB2\u8DEF\u5BB9\u91CF\u53CA\u4F7F\u7528\u73FE\u6CC1\u9031\u8868.xls"; > String tmp = "f:/temp/91.xls"; > ExcelParser excelParser = new ExcelParser(tmp); > excelParser.getNewestSheet(); > //ExcelParser excelParser = new ExcelParser("C:\\temp\\\u7DB2\u8DEF\u5BB9\u91CF\u53CA\u4F7F\u7528\u73FE\u6CC1\u9031\u8868-2-diagram(\u8655\u9577\u6307\u793A).xls"); >//-------------------read the newest date----------------------------------------------- > File file = new File("kkk.txt"); > FileInputStream fiStream = new FileInputStream(file); > InputStreamReader reader = new InputStreamReader(fiStream, "MS950"); > BufferedReader br = new BufferedReader(reader); > String newestDate = br.readLine(); > String newestDateOfExcelnFile = excelParser.getNewestDateString(); > if(newestDate.equals(newestDateOfExcelnFile)){ > // there is not newer sheet > System.out.println("There has no newer sheet, System exit!!!!!!"); > System.exit(0); > }//end if > else if(Integer.parseInt(newestDateOfExcelnFile)>Integer.parseInt(newestDate)) { > // there has a newer sheet >//--------------write the newest date----------------------------------------------- > //do nothing > }//end else if > else{ > System.out.println("This could not never be happen, System exit"); > System.exit(0); > }//end else > conn =getConnection(); >// -------------------------------strt to check the title------------- > //ps = conn.prepareStatement("insert into Volume_Title values(\'\u9805\u76EE\',\'\u5206\u516C\u53F8\',\'\u81F390\u5E7412\u6708\u7D2F\u8A08\u6578\',\'91\u5E74\u9810\u5B9A\u5EFA\u8A2D\u6578\',\'\u5EFA\u8A2D\u57F7\u884C\u73FE\u6CC1(%)\')"); > ps = conn.prepareStatement("select * from Infrastructure_Title"); > rs=ps.executeQuery(); > row = excelParser.sheet.getRow(2); > String[] strings = new String[5]; > // assign tables title to string array > //System.out.println(rs.getString("Item")); > if(rs.next()){ > for(int i=0;i<5;i++){ > strings[i] = rs.getString(i+1); > }//end for > }//end if >// compart to the row data > if (!strings[2].equals(row.getCell((short)7).getStringCellValue())) > insertIntoInfrastructureTitle(row.getCell((short)1).getStringCellValue(),row.getCell((short)3).getStringCellValue(),row.getCell((short)7).getStringCellValue(),row.getCell((short)8).getStringCellValue(),row.getCell((short)9).getStringCellValue(),conn); > if (!strings[3].equals(row.getCell((short)8).getStringCellValue())) > insertIntoInfrastructureTitle(row.getCell((short)1).getStringCellValue(),row.getCell((short)3).getStringCellValue(),row.getCell((short)7).getStringCellValue(),row.getCell((short)8).getStringCellValue(),row.getCell((short)9).getStringCellValue(),conn); > if (!strings[4].equals(row.getCell((short)9).getStringCellValue())) > insertIntoInfrastructureTitle(row.getCell((short)1).getStringCellValue(),row.getCell((short)3).getStringCellValue(),row.getCell((short)7).getStringCellValue(),row.getCell((short)8).getStringCellValue(),row.getCell((short)9).getStringCellValue(),conn); >//-----------check title of volumn----------- > ps = conn.prepareStatement("select * from Volume_Title"); > rs = ps.executeQuery(); > row = excelParser.sheet.getRow(2); >//---------String[] strings = new String[5]; > // assign tables title to string array > if(rs.next()){ > for(int i=0;i<5;i++){ > strings[i] = rs.getString(i+1); > }//end for > }//end if// compart to the row data > if (!strings[2].equals(row.getCell((short)4).getStringCellValue())) > insertIntoVolumeTitle(row.getCell((short)1).getStringCellValue(),row.getCell((short)3).getStringCellValue(),row.getCell((short)4).getStringCellValue(),row.getCell((short)5).getStringCellValue(),row.getCell((short)6).getStringCellValue(),conn); > if (!strings[3].equals(row.getCell((short)5).getStringCellValue())) > insertIntoVolumeTitle(row.getCell((short)1).getStringCellValue(),row.getCell((short)3).getStringCellValue(),row.getCell((short)4).getStringCellValue(),row.getCell((short)5).getStringCellValue(),row.getCell((short)6).getStringCellValue(),conn); > if (!strings[4].equals(row.getCell((short)6).getStringCellValue())) > insertIntoVolumeTitle(row.getCell((short)1).getStringCellValue(),row.getCell((short)3).getStringCellValue(),row.getCell((short)4).getStringCellValue(),row.getCell((short)5).getStringCellValue(),row.getCell((short)6).getStringCellValue(),conn); > // ----------------end compare to the row data----------- >//---------------move all old infrastructure data ------------------------------------ > SimpleDateFormat formatter //[ /messa-elintdelete.jsp; Line: 225] > = new SimpleDateFormat ("yyyy/MM/dd"); > java.util.Date date = new java.util.Date(); > ps = conn.prepareStatement("insert into Network_Infrastructure_History select to_date(\'"+formatter.format(date)+"\', \'yyyy/mm/dd\'),Item,Department,Goal,Perform,Percentage from Network_Infrastructure"); > ps.executeQuery(); > ps = conn.prepareStatement("delete from Network_Infrastructure"); > ps.executeQuery(); >//---------------move all old volume data ------------------------------------ > ps = conn.prepareStatement("insert into Network_Volumne_History select to_date(\'"+formatter.format(date)+"\', \'yyyy/mm/dd\'),Item,Department,Volumne,Usage,Percentage from Network_Volumne"); > ps.executeQuery(); > ps = conn.prepareStatement("delete from Network_Volumne"); > ps.executeQuery(); > conn.commit(); > excelParser.getNewestSheet(); > String item,department,volume,usage,goal,perform,percentage = ""; > NumberFormat numberFormat = NumberFormat.getInstance(); > numberFormat.setMaximumFractionDigits(2); >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- > String kkkkk =new String("\u5E02\u8A71\u4EA4\u63DB\u6A5F\u9580\u865F\u6578(POTS)".getBytes(),"big5"); > row = excelParser.getRowByName(kkkkk); > // start to insert data for North dep--------------- > //construct the database data > item = kkkkk; > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)7).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)8).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)8).getNumericCellValue()/row.getCell((short)7).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoVolume(item,department,volume,usage,percentage,conn); > // --------------for center dep---------------- > row = excelParser.getNextRow(row); > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)7).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)8).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)8).getNumericCellValue()/row.getCell((short)7).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoVolume(item,department,volume,usage,percentage,conn); > // --------------for sourth dep---------------- > row = excelParser.getNextRow(row); > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)7).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)8).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)8).getNumericCellValue()/row.getCell((short)7).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoVolume(item,department,volume,usage,percentage,conn); >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- > kkkkk =new String("\u9577\u8A71\u4EA4\u63DB\u6A5F\u9580\u865F\u6578".getBytes(),"big5"); > row = excelParser.getRowByName(kkkkk); > // start to insert data for North dep--------------- > //construct the database data > item = kkkkk; > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)7).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)8).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)8).getNumericCellValue()/row.getCell((short)7).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoVolume(item,department,volume,usage,percentage,conn); >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- > kkkkk =new String("\u570B\u969B\u4EA4\u63DB\u6A5F\u9580\u865F\u6578".getBytes(),"big5"); > row = excelParser.getRowByName(kkkkk); > // start to insert data for North dep--------------- > //construct the database data > item = kkkkk; > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)7).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)8).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)8).getNumericCellValue()/row.getCell((short)7).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoVolume(item,department,volume,usage,percentage,conn); >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- > kkkkk =new String("\u5E02\u8A71\u4EA4\u63DB\u6A5F\u9580\u865F\u6578(POTS)".getBytes(),"big5"); > row = excelParser.getRowByName(kkkkk); > // start to insert data for North dep--------------- > //construct the database data > item = kkkkk; > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); > // --------------for center dep---------------- > row = excelParser.getNextRow(row); > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); > // --------------for sourth dep---------------- > row = excelParser.getNextRow(row); > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- > kkkkk =new String("\u9577\u8A71\u4EA4\u63DB\u6A5F\u9580\u865F\u6578".getBytes(),"big5"); > row = excelParser.getRowByName(kkkkk); > // start to insert data for North dep--------------- > //construct the database data > item = kkkkk; > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); >//------------------------------------------------------------------------------------------------------- > kkkkk =new String("\u5BEC\u983B\u4E0A\u7DB2ADSL\u8A2D\u5099".getBytes(),"big5"); > row = excelParser.getRowByName(kkkkk); > // start to insert data for North dep--------------- > //construct the database data > item = kkkkk; > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); > // --------------for center dep---------------- > row = excelParser.getNextRow(row); > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); > // --------------for sourth dep---------------- > row = excelParser.getNextRow(row); > department =row.getCell((short)3).getStringCellValue(); > volume = numberFormat.format(row.getCell((short)4).getNumericCellValue()); > usage = numberFormat.format(row.getCell((short)5).getNumericCellValue()); > percentage = numberFormat.format(row.getCell((short)5).getNumericCellValue()/row.getCell((short)4).getNumericCellValue()*100)+"%"; > // --------------write this row to the database > insertIntoInfrastructure(item,department,volume,usage,percentage,conn); >//------------------------------------------------------------------------------------------------------- >//------------------------------------------------------------------------------------------------------- > conn.commit(); > conn.close(); > FileOutputStream foStream = new FileOutputStream(file); > foStream.write(newestDateOfExcelnFile.getBytes()); > }//end try > catch(Exception e){ > System.out.println("Go to working , there are some thing happen!!!!!!!!!!!"); > e.printStackTrace(); > } >}//end main > >public static void insertIntoInfrastructure(String _item,String _department,String _goal,String _perform,String _percentage,Connection _conn){ > try{ > PreparedStatement ps = null; > ps = _conn.prepareStatement("insert into Network_Infrastructure values (?,?,?,?,?)"); > ps.setString(1,_item); > ps.setString(2,_department); > ps.setString(3,_goal); > ps.setString(4,_perform); > ps.setString(5,_percentage); > ps.executeQuery(); > }//end try > catch(Exception e){ > e.printStackTrace(); > } >}//end end >//------------------------------------------------------------ >public static void insertIntoVolume(String _item,String _department,String _volumne,String _usage,String _percentage,Connection _conn){ > try{ > PreparedStatement ps = null; > ps = _conn.prepareStatement("insert into Network_Volumne values (?,?,?,?,?)"); > ps.setString(1,_item); > ps.setString(2,_department); > ps.setString(3,_volumne); > ps.setString(4,_usage); > ps.setString(5,_percentage); > ps.executeQuery(); > }//end try > catch(Exception e){ > e.printStackTrace(); > } >}//end end >//------------------------------------------------------------ >public static void insertIntoInfrastructureTitle(String _item,String _department,String _goal,String _perform,String _percentage,Connection _conn){ > try{ > System.out.println("InfrastructureTitle has been changed , please do a further recheck!!!!!!!"); > PreparedStatement ps = null; > ps = _conn.prepareStatement("delete from Infrastructure_Title"); > ps.executeQuery(); > ps = _conn.prepareStatement("insert into Infrastructure_Title values (?,?,?,?,?)"); > ps.setString(1,_item); > ps.setString(2,_department); > ps.setString(3,_goal); > ps.setString(4,_perform); > ps.setString(5,_percentage); > ps.executeQuery(); > }//end try > catch(Exception e){ > e.printStackTrace(); > } >}//end end >//------------------------------------------------------------ >public static void insertIntoVolumeTitle(String _item,String _department,String _volumne,String _usage,String _percentage,Connection _conn){ > try{ > System.out.println("VolumeTitle has been changed , please do a further recheck!!!!!!!"); > PreparedStatement ps = null; > ps = _conn.prepareStatement("delete from Volume_Title"); > ps.executeQuery(); > ps = _conn.prepareStatement("insert into Volume_Title values (?,?,?,?,?)"); > ps.setString(1,_item); > ps.setString(2,_department); > ps.setString(3,_volumne); > ps.setString(4,_usage); > ps.setString(5,_percentage); > ps.executeQuery(); > }//end try > catch(Exception e){ > e.printStackTrace(); > } >}//end end >public static Connection getConnection(){ > // set up the prepare statment > int groupID =0; > int userID=0; > String content =""; > String driver_ora="oracle.jdbc.driver.OracleDriver"; > String url_ora="jdbc:oracle:thin:@10.144.134.143:1522:ORCL"; > String userID_ora="scott"; > String password_ora="ima320"; > Vector v = new Vector(); > Connection DBCon_ora =null; > try { > Class.forName(driver_ora);//.newInstance(); > } > catch(Exception e) { > System.out.println("Unable to load oracle.jdbc.driver.OracleDriver() driver!"); > //System.out.println("Unable to load " + driver_ms + " driver!"); > e.printStackTrace(); > } > try{ > DBCon_ora = DriverManager.getConnection(url_ora, userID_ora, password_ora); > if (!DBCon_ora.isClosed()) > ;//S//ystem.out.println("Successfully connected to Oracle DB!"); > > if (DBCon_ora.getAutoCommit()) > ;//S//ystem.out.println("Auto Commit!"); > else > ;//S//ystem.out.println("Not Auto Commit!"); > DatabaseMetaData DBMsg_ora = DBCon_ora.getMetaData(); > > System.out.println("Database Name: " + DBMsg_ora.getDatabaseProductName()); > System.out.println("Version: " + DBMsg_ora.getDatabaseProductVersion()); > System.out.println("JDBC Driver: " + DBMsg_ora.getDriverName()); > System.out.println("JDBC Version: " + DBMsg_ora.getDriverVersion()); > System.out.println("Database URL: " + DBMsg_ora.getURL()); > System.out.println("Account: " + DBMsg_ora.getUserName()); > }//end try > catch(SQLException e) { > //S//ystem.out.println("Unable to connect to Oracle DB!"); > //S//ystem.out.println("Unable to connect to MSSQL DB!"); > e.printStackTrace(); > } > catch(Exception e) { > //S//ystem.out.println("Exception!"); > e.printStackTrace(); > } > > System.out.println(content); > return DBCon_ora; > > }//end >//---------------------------------------------------------------------------- > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 12843
: 3309 |
3310
|
3311
|
3962
|
4098
|
4130