mysqlテーブル列名Num1、num2、num3、num4、num5、num6テーブル名Excel
アップロード方法
パッケージcom.web.connection; import java.io.fileinputStream; Import java.io.fileenotfoundectection; Import java.io.ioexception; Import org.apache.commons.logging.log; Import org.apache.commons.logging.logging.logfactory; org.apache.poi.usermodel.hssfrow; Import org.apache.poi.hssf.usermodel.hssfsheet; Import org.apache.poi.hssf.usermodel.hssfworkbook; Import org.apache.poi.xsf.sf.usermodel.xsf. org.apache.poi.xssf.usermodel.xssfrow; Import org.apache.poi.xsf.usermodel.xssfsheet; import org.apache.poi.xssf.usermodel.xssfworkbook; public class testexcel {//クラスの統計情報の出力科学情報の記録logfactory.getLog(testexcel.class); // xssfworkbookを使用してexcelドキュメントへのパスを取得します。 xssfworkbook(new fileinputStream(filepath)); // excelドキュメントでは、最初のワークシートのデフォルトインデックスは0 //そのステートメントは次のものです。hssfsheetシート= workbook.getsheetat(0); xssfsheet sheet = wookbook.getsheet( "sheet1"); sheet.getPhysicalNumberOfRows(); // transweep for(int i = 0; i <rows; i ++){//左上のセルxssfrow row = sheet.getrow(i); ""; //(int j = 0; j <cells; j ++){//列xssfcell cell = row.getcell(j); if(cell!= null){sell.getCelltype()){case hssfcell.cell_type_formula:break hssfceltel. += cell.getNumericCellValue() +"、"; break; case hssfcell.cell_type_string:value += cell.getStringCellValue() +" +"、 "; break; value +=" 0 ";}}} // mysqlデータベースにデータを挿入します。 testentity(); entity.setnum1(val [0]); entity.setnum2(val [1]); entity.setnum3(val [2]); entity.setnum4(val [3]); entity.setnum5(val [4]); entity.setnum6(val [5]); testmethod method = new testmethod(); a = method.add(entity); if(a> 0){system.out.println( "insert sucture");} else {system.out.println( "insert failed");}}}}}}}}} {e.printstacktrace();} catch(){exexception e)ここでは、Excelテーブルから照会されたデータを保存するエンティティクラスです。
パッケージcom.web.connection; public class testentity {private string num1; private string num2; private string num4; private string num4; private string num6; public string getnum1(){} public void num1;} public void setnum1(){return num1(){this.num1 = num1;} num1;} num1;} setnum2(string num2){this.num2 = num2;} public string getnum3(){return num3;} public void setnum3(string num3){this.num3 = num3;} public string getnum4(){return num4;} public void setnum4(return num4;} num4;} num4;} num5;} public void setnum5(string num5){this.num5 = num5;} public string getnum6(){return num6;} public void setnum6(string num6){this.num6 = num6;}}}TestMethodは、MySQLテーブルにデータを挿入するSQLステートメントです
パッケージcom.web.connection; import java.sql.connection; import java.sql.preparedStatement; import java.sql.sql.sqlecception; public class testmethod {public int(testentity te){connection con = dbconnection.getConnection() excel(num1、num2、num3、num4、num5、num6)values(?、、?、?、?) "; try {pstmt = con.preparestatement(sql); pstmt.setstring(1、te.getnum1()); pstmt.setstring(2、te.getnum2(); te.getnum3()); pstmt.setString(4、te.getnum4()); pstmt.setstring(5、te.getnum5()); pstmt.setstring(6、te.getnum6(); count = pstmt.exexecteupdate(); ** if(count == 0); }*/} catch(sqlexception e){// dodo auto-fenated catch blocke.printstacktrace();} fultry {try {pstmt.close();} catch(sqlecception e){// todo auto-jenerated catch blocke.printstrace( count;}}要約します
上記は、JavaのMySQLインスタンスコードにExcelコンテンツをアップロードすることに関するこの記事の全体的な内容です。私はそれが誰にでも役立つことを願っています。興味のある友人は、このサイトの他の関連トピックを引き続き参照できます。欠点がある場合は、それを指摘するためにメッセージを残してください。このサイトへのご支援をありがとうございました!