내 일관된 스타일 인 코드는 모든 것을 말합니다. .
나는 말도 안되는 말을하지 않을 것입니다. 나는 당신에게 코드를 게시 할 것입니다. 특정 코드는 다음과 같습니다.
패키지 도구; import java.io.bufferedwriter; import java.io.file; import java.io.filewriter; import java.io.ioexception; import java.lang.reflect.field; import java.util.arraylist; import java.util.list; gortiv jxl.sheet; jxl.worke enterbook; Entity; XLS 테이블에서 데이터를 얻고 데이터베이스에 삽입 할 수있는 실행 가능한 SQL 파일을 생성합니다. JXL 패키지를 소개해야합니다! Support int,Integer,long,Long,String* , can be expanded by itself * * @param args* @throws IllegalArgumentException* @throws IllegalAccessException*/public static void main(String[] args) throws IllegalArgumentException,IllegalAccessException {// Get all the data in the table List<Student> listExcel = getAllByExcel ( "c : //users//xxx//desktop//zzz.xls"); try {string path = "c : //users//xxx//desktop//convert.sql"; // 파일 저장 경로 및 이름 파일 = 새 파일 (Path); bufferedwiter (piperedwiter); ListExcel) {String SQL = "CFG_AVATAR 값 (" + outSQL (C) + ")"; ow.write (sql + ";" + "/n");} // write content ow.close ();} catch (ioexception e) {e.printstacktrace ()}/* xls에서 xls get get get get get get get get get get get get get get get get get get get get get get get get get get get. @return*/public static list <gulde> getAllByExcel (String file) {list <nody list = new arraylist <nogy (); try {workbook rwb = workbook.getWorkbook (새 파일 (파일)); 시트 rs = rwb.getsheet (0); int clos = rs.getColumns (); // get Rows (get Rows) 예를 들어, 데이터는 (int i = 2; 나는 <줄; I ++) {// 획득 된 각 행의 모든 데이터는 ListStringList <string> listString = new ArrayList <string> ()에 저장됩니다. for (int j = 0; j <clos; j ++) {string str = rs.getCell (j, i) .getContents (); listString.add (str);} 학생 학생 = (학생) newObject (new student (), ListString); list.add (학생);}} 캐치 (예외 e) {e.printstacktrace (); 이 예제에서 설정할 수있는 데이터 유형은 제한되어 있지 않으므로 그렇지 않은 경우 직접 추가하십시오! ! ! *** @param obj* @param list* @return* @throws 불법 행위 exception* @throws 불법 대상 NewObject (Object Obj, List <string> 목록) 불법적 인 {field [] field [] field = obj. field.length; i ++) {field f = field [i]; f.setAccessible (true); if (f.getType () == String.class) {f.set (obj, list.get (i));} if (f.getType () == integer.class) {f.set (obj, integer.per.per. (f.getType () == int.class) {f.set (obj, integer.parseint (list.get (i));} if (f.getType () == long.class) {f.set (obj, long.parselong (list.get (i))); if (f.getType () == long.class) {f.class) {f.class) long.parselong (list.get (i));}} return obj;}/**** @param obj* @return* @throws 불법적 인 strows 불법 행위 exception*/public static string outsql (Object obj) throws obj) 불법적 인 strows (obj) 불법적 인 strows (stringbufer) (new stringbufter); = obj.getClass (). getDeclaredFields (); for (int i = 0; i <field.length; i ++) {field f = field [i]; f.setAccessible (true); if (f.getType () == string.class) {buffer.Append ( " '");} buffer.Append (f.get (obj)); if (f.getType () == string.class) {bucter.append (if <field.1); {buffer.append ( ",");}} return buffer.toString ();}}}Excel XLS에서 데이터를 변환하는 Java 구현에 대한 지식과 관련하여 데이터베이스에 직접 삽입 할 수있는 SQL 파일로 데이터를 변환 할 수 있으므로 편집기가 귀하에게 많은 것을 소개합니다. 도움이되기를 바랍니다.