1. 数组越界异常
具体报错
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 23 out of bounds for length 23 at com.company.Test1$Grant.run(Test1.java:52) at com.company.Test1.main(Test1.java:65)
报错原因
是因为数组中的下标过界,超出范围,所以报此错误
for (int i = 0; i<=arr_grant.length; i++) {
}
解决方法
public static class Grant {
public void run() throws SQLException, IOException {
Connection conn = HostMulti.startThreadConn1();
Statement st = conn.createStatement();
BufferedReader retable = null;
retable = new BufferedReader(new FileReader("/server/scipts/modify_data.sql"));
// Read one line at a time
String[] arr_grant = {"update", "insert", "select"};
List<String> result = new ArrayList<>();
String lineContent = null;
while ((lineContent=retable.readLine()) != null) {
// System.out.println(retable.readLine());
result.add(lineContent);
result.toArray();
}
for (int i = 0; i<arr_grant.length; i++) {
for (int j = 0; j < result.toArray().length; j++) {
//System.out.println(result[j]);
System.out.println("grant "+arr_grant[i] +"(" + result.toArray()[j] +") on test.table_1_utf8_4 to 'user1'@'%'");
}
return;
}
}
}
2. jdbc连接mysql驱动错误
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
解决方法:
//驱动改为
com.mysql.cj.jdbc.Driver
3. java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying
解决方法:
//在连接mysql的jdbc中加入
bc:mysql://localhost:3306/tree?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT