Saturday, March 7, 2015

Inserting Data from Java
































































Hello, I am new to JDCB.I have done an example and I was able to connect to the database, but I need help inserting data that I read from a txt file.































































So, I created an object that holds my int, String String, String String. I am supposed to read in each data and insert into the appropriate record. Any help? or suggestions?































































This is my data reader.
































































































Java Code:






































































ArrayList<locations> locations = new ArrayList<locations>();
String fileName = "locations.txt";


try {
FileReader input = new FileReader(fileName);

BufferedReader bf = new BufferedReader(input);

String line;

while((line = bf.readLine()) !=null){


String[] tokens = line.split(",");
locations.add(new locations(Integer.parseInt(tokens[0]), tokens[1], tokens[2], tokens[3], tokens[4]));



}
bf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//Testing
for(locations l : locations){

System.out.println(l.getAddress());


}


}



































































































































No comments:

Post a Comment