I'm trying to input my details in MySQL using Java. But I keep on having following error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?, ?)' at line 1
Here is my code:
Vehicle vehicle = new Vehicle();
int vType;
System.out.println("Please enter Vehicle Type\n1 = Car\n2 = Van\n3 = Motorbike\n4 = Motorbike");
vType = input.nextInt();
if (vType==1){
System.out.println("Car Brand: ");
vehicle.setvBrand(input.next());
System.out.println("Car License Plate: ");
vehicle.setvLicense(input.next());
try {
Connection dbConn = DriverManager.getConnection(url,user,pass);
String parkCar = "INSERT INTO car_park_details(vehicle_brand, vehicle_license) values( ?, ?)";
PreparedStatement park = dbConn.prepareStatement(parkCar);
park.executeUpdate(parkCar);
park.setString(2,vehicle.getvBrand());
park.setString(3, vehicle.getvLicense());
park.execute();
System.out.println("Try daw check sa DB MYONG!");
}
catch (Exception ex){
System.out.println("Error" + ex);
}
}
Am I doing it wrong? I'm a begginer Java Developer. thanks for the help.
park.executeUpdate(parkCar);park.executeUpdate()with no parameters, and then delete thepark.execute()line below it.