MCPcopy Index your code
hub / github.com/epcdiy/timemachineplus / importSql

Method importSql

src/main/java/MySQLHelper.java:120–201  ·  view source on GitHub ↗
(String filePath)

Source from the content-addressed store, hash-verified

118 }
119
120 public boolean importSql(String filePath)
121 {
122 logger.info("sql importing "+filePath);
123 StringBuilder sqlline=new StringBuilder("");
124 File file = new File(filePath);
125 if(file.exists()&&file.isFile())
126 {
127
128 int curpackage=0;
129 int cnt=0;
130 try
131 {
132 if(!conn.isValid(1000))
133 {
134 if(!init())
135 {
136 return false;
137 }
138 }
139 conn.setAutoCommit(false);
140 Statement stmt = conn.createStatement();
141 InputStreamReader read = new InputStreamReader(
142 new FileInputStream(file), "UTF-8");// 考虑到编码格式
143 BufferedReader bufferedReader = new BufferedReader(read);
144 String lineTxt = "";
145 sqlline=new StringBuilder("");
146 while ((lineTxt = bufferedReader.readLine()) != null)
147 {
148 sqlline.append(lineTxt);
149 if(sqlline.indexOf(";")!=-1)
150 {
151 stmt.addBatch(sqlline.toString());
152 curpackage+=sqlline.length();
153 if(curpackage>maxpackage)
154 {
155 curpackage=0;
156 logger.debug("executeBatch:"+stmt.executeBatch().length);
157 conn.commit();
158 }
159 sqlline=new StringBuilder("");
160 cnt++;
161 }
162
163 }
164 bufferedReader.close();
165 read.close();
166 if(curpackage>0)
167 {
168 curpackage=0;
169 logger.debug("final executeBatch:"+stmt.executeBatch().length);
170 conn.commit();
171 }
172 logger.info("imported "+cnt+" lines");
173 conn.setAutoCommit(true);
174 stmt.close();
175 return true;
176 }
177 catch (Exception e)

Callers

nothing calls this directly

Calls 2

initMethod · 0.95
closeMethod · 0.80

Tested by

no test coverage detected