Bear in mind that this is a pretty greenhorn-question, so please, be patient with me.
So as a person who knows little to nothing about databases, undesirable conditions have lead me into a situation where I am to perform a task I know little about how to do.
In my hour of need, I come to you guys/gals.
Firstly, my task requires me to use Apache Derby to achieve the desired goals alongside Eclipse.
I've been given a single database located at res/myCSVFile.csv.
The text file with the CSV extension looks like this:
letter,name
A,alpha-static
B,beta-static
C,charlie-static
Doesn't look too threatening, right?
I know I can build a nice HashMap out of my CSV file like this:
Map<String, myFileType> myHashMap = new HashMap<>();
try(CSVReader rdr = new CSVReader(new FileReader("res/myCSVFile.csv"), ',','"',1)){
for(String[] row : rdr.readAll()){
File imagefile = new File(row[1]);
myHashMap.put(row[0], new myFileType(imagefile, Integer.parseInt(row[2])));
}
}
I know CSV separates columns by commas, so I assume what I see in this file are two columns, one labeled "letter" with the values "A", "B" and "C" under it, and another labeled "name" with "alpha-static", "beta-static" and "charlie-static" under it.
My situation requires me to use Derby to manipulate the above data as an SQL database. Knowing full well that a CSV file looks nothing like a SQL file, I know there is some conversion involved.
I don't know if Java can (or should) do this for me somehow, but I assume not.
Now, I do presume the SQL variant of my CSV file would look something like:
DROP TABLE possibleSqlTable;
CREATE TABLE possibleSqlTable(
letter VARCHAR(1) NOT NULL PRIMARY KEY
, name VARCHAR(14)
);
INSERT INTO possibleSqlTable(letter,name) VALUES ('A','alpha-static');
INSERT INTO possibleSqlTable(letter,name) VALUES ('B','beta-static');
INSERT INTO possibleSqlTable(letter,name) VALUES ('C','charlie-static');
That's just my guess in the dark at how this SQL database would look (correct me if I'm wrong). Assume that's saved as res/possibleSqlDatabase.sql.
Now, how do I get Derby in on the action?
Assuming my SQL database is correct as I've guessed above, how do I for example query a statement?
How would I, for example, map "A" to "alpha-static"? Can I do this with a simple HashMap? I'd love to see how, if that'd be possible.
I do have a basic, VERY basic, understanding of how SQL-commands work, but I would love some examples using my database.
When answering, just treat me like a preschooler trying to learn this stuff. I really am that new.
EDITs in the question body - there's a place for them called Edit Summary.