Nonononono! Don't mess about with arrays, least of all with nesting, and don't use Strings when you could write a proper datatype. Create an airport class with code and name and location fields. Consider verifying those fields before creating the objects, so the code field would have three capital letters. Depending on how experienced you are, you can test whether the code matches a suitable regular expression, or you can test its length (=3) and that each of its constituent characters is an upper‑case letter. If not, throw an illegal argument exception and work out what is happening. Maybe airports are allowed to have four letters in their codes (Wikipedia page). Anyway, it appears that you are trying to put something longer than three letters into an SQL field taking three letters.Daniel Chivelly wrote:. . . a dynamic 2D array and then convert it to a string . . .
Campbell Ritchie wrote:
Nonononono! Don't mess about with arrays, least of all with nesting, and don't use Strings when you could write a proper datatype. Create an airport class with code and name and location fields. Consider verifying those fields before creating the objects, so the code field would have three capital letters. Depending on how experienced you are, you can test whether the code matches a suitable regular expression, or you can test its length (=3) and that each of its constituent characters is an upper‑case letter. If not, throw an illegal argument exception and work out what is happening. Maybe airports are allowed to have four letters in their codes (Wikipedia page). Anyway, it appears that you are trying to put something longer than three letters into an SQL field taking three letters.Daniel Chivelly wrote:. . . a dynamic 2D array and then convert it to a string . . .
How are you splitting the line? Why are you using \t? I can see no tabs in what you showed; the text seems to be separated by commas. Splitting on tabs won't work, and won't produce a bit of text three letters long.
* * * * * * *
Don't try reading the file and inserting into the database in the same place if you can help it. Separate the concerns and separate the problems which might arise. That isn't the right way to create and close a buffered reader any more.
Use BufferedReader reader = Files.newBufferedReader(Paths.get(textToPath));
Don't call close(): use try with resources instead:-Since you are doing the same for both kinds of exception, try a multi‑catch instead (as above).
Avoid += on Strings; the problem isn't as bad as it used to be, but you are risking slow execution. Use a prepared statement, or use a StringBuilder object to build your query text.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
You have done nothing to apologise for.Daniel Chivelly wrote:haha I apologise
That's a pleasureif what I suggested had made you split hairs. . . . thank you,
You aren't at University simply to learn things, but to learn how to learn things. When I was an undergraduate, we learnt from lectures, practicals, books, papers, and one another. Now you also have the opportunity to learn from experienced people on fora; if we try to help you, please accept that help.This is only for a university project so the requirements aren't crazy extensive and I don't feel comfortable trying things for this particular assignment.
You would have known that if you had read the documentation beforehand. Unless you are using something you are very familiar with, read its documentation. But your comment makes me wonder whether you understand where the splitting problem is occurring. Remember that lines aren's terminated by tabs.. . . , i've realised now that the statement >thisLine = br.readLine()< already splits it by line . . .
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
|