Here is my LinkedList
LinkedList<Location> locationData = new LinkedList<>();
Here is my Location class variables
public class Location {
String SA3Code;
String name;
}
QUESTION: I want to insert this locationData LinkedList inside method
List of SA3Code and name values should insert into database
I've tried to insert values as following, but it gives an error of "Data too long"
public void InsertLocations(LinkedList<Location> locationData) throws SQLException {
for (int i = 0; i < locationData.size(); i++) {
statement.executeUpdate("INSERT INTO HomelessInfo.Location (SA3Code, Name) VALUES ('locationData.get(i).SA3Code', 'locationData.get(i).name')");
}
connection.close();
}
ERROR
Exception in thread "main" com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Data too long for column 'SA3Code' at row 1
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:104)
at com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1335)
at com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2108)
at com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1245)
at Homeless.DatabaseUtility.InsertLocations(DatabaseUtility.java:42)
at Homeless.DataFile.readRecords(DataFile.java:98)
at Homeless.COIT20256Assignment2.main(COIT20256Assignment2.java:20)
/Users/SK/Library/Caches/NetBeans/8.2rc/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)
