salam kwn2,saya de mslh nak masukkan element(column) yang user input ke database.untuk pengetahuan,saya sudah dapat connect dengan database,tp column yang user select masih lagi tidak masuk ke database.mohon pertolongan untuk selesaikan masalah ni.terima kasih
//filename = student.csv(name,matric,gender,state,faculty)
//link image output = http://www.imgplace.com/viewimg23/719/45java.jpg
//method select column file
public void selectfile(){
System.out.println("==========================================");
System.out.println("\tSelect column from "+filename);
System.out.println("==========================================");
Vector<Integer> choiceList = new Vector<Integer>();
int choice =0;
System.out.println("\t1 : column 1");
System.out.println("\t2 : column 2 and so on");
System.out.println("\t-1 : End choices");
System.out.println("===========================================");
System.out.println();
while (choice != -1) {
System.out.print("Please enter your choice :");
Scanner option = new Scanner(System.in);
choice = option.nextInt();
choiceList.add(choice);
}
try{
BufferedReader file = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(filename)));
input = new Scanner(file);
System.out.println();
String sql = "INSERT INTO student(name,matric,gender,state,faculty) VALUES (?,?,?,?,?)";
PreparedStatement pstmt= MysqlUtility.getConnection().prepareStatement(sql);
while ( input.hasNext()) {
String line = input.next();
data = line.split(",");
for (int i=0;i<data.length; i++) {
for(int j=0; j<choiceList.size();j++) {
int choice_no = choiceList.elementAt(j);
if (choice_no == i+1)
System.out.print(data[i]);
pstmt.setString(i++,data[i]);
}
}
System.out.println("");
}
pstmt.close();
file.close();
input.close();
//System.out.println("success insertion");
}
catch (Exception e) {
System.out.println("getFileContentsAsStringError(): " + filename + "\n" + e);
//throw e;
}
}