This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
com.mysql.jdbc.Connection unwrapped = connection.unwrap(com.mysql.jdbc.Connection.class); | |
unwrapped.setAllowLoadLocalInfile(true); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String LOADDATA = "LOAD DATA LOCAL INFILE '' INTO TABLE `bike_trip` " | |
+ "CHARACTER SET UTF8 FIELDS TERMINATED BY '\t' ENCLOSED BY '' " | |
+ "ESCAPED BY '\\\\' LINES TERMINATED BY '\n' STARTING BY '' " | |
+ "(tripduration, starttime, stoptime, start_station_id, start_station_name, " | |
+ "start_station_latitude, start_station_longitude, end_station_id, " | |
+ "end_station_name, end_station_latitude, end_station_longitude, " | |
+ "bike_id, user_type, birth_year, gender)"; | |
int cont = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (cont % batchSize == 0) { | |
InputStream is = new ByteArrayInputStream(sb.toString().getBytes()); | |
Statement statement = (Statement) unwrapped.createStatement(); | |
statement.setLocalInfileInputStream(is); | |
statement.execute(LOADDATA); | |
sb.setLength(0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PgConnection unwrapped = connection.unwrap(PgConnection.class); | |
CopyManager copyManager = unwrapped.getCopyAPI(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String COPY = "COPY bike_trip (tripduration, starttime, stoptime," | |
+ "start_station_id, start_station_name, start_station_latitude, " | |
+ "start_station_longitude, end_station_id, end_station_name," | |
+ "end_station_latitude, end_station_longitude, bike_id," | |
+ "user_type, birth_year, gender)" | |
+ " FROM STDIN WITH (FORMAT TEXT, ENCODING 'UTF-8', DELIMITER '\t'," | |
+ " HEADER false)"; | |
int cont = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (cont % batchSize == 0) { | |
InputStream is = new ByteArrayInputStream(sb.toString().getBytes()); | |
copyManager.copyIn(COPY, is); | |
sb.setLength(0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
private Integer id; | |
private String name; | |
public Person(Integer id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
private Integer id; | |
private String name; | |
public Person(Integer id, String name) { | |
this.id = id; | |
this.name = name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int hashCode(Object a[]) { | |
if (a == null) return 0; | |
int result = 1; | |
for (Object element : a) | |
result = 31 * result + (element == null ? 0 : element.hashCode()); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyObject { | |
private MyObjectKey key; | |
private String someAttribute; | |
public MyObject(int firstKey, int secondKey, String someAttribute) { | |
this.key = new MyObjectKey(firstKey, secondKey); | |
this.someAttribute = someAttribute; | |
} |