Ive given my Strings, ints and floats variables, and tried to insert the variables into a table in access using SQL, But it gives some errors, firstly:
public static void addItem(String value1, String value2, int value3, int value4, float value5)
{
System.out.println("Enter value1: ");
Scanner input = new Scanner(System.in);
value1 = input.next();
System.out.println("Enter value2: ");
value2 = input.next();
System.out.println("Enter value3: ");
value3 = input.nextInt();
System.out.println("Enter value4: ");
value4 = input.nextInt();
System.out.println("Enter value5: ");
value5 = input.nextFloat();
try
{
String insert = "INSERT INTO myDatabase"
+ " VALUES(value1,value2,value3,value4,value5)";
statement.executeUpdate(insert);
}
catch(SQLException e)
{
System.out.println("* Cannot execute query! *");
e.printStackTrace();
System.exit(1);
}
------------------------------------------------------------
So why wont the variables work when inserted into my database? i cant think of another way of doing it, any reasons why this doesnt work?
Also, in main, under addItems() it says: The method addItem(String, String, int, int, float) in the type StockAccess is not applicable for the
arguments () I dont know what arguments to pass in main where string, string etc were.
public static void addItem(String value1, String value2, int value3, int value4, float value5)
{
System.out.println("Enter value1: ");
Scanner input = new Scanner(System.in);
value1 = input.next();
System.out.println("Enter value2: ");
value2 = input.next();
System.out.println("Enter value3: ");
value3 = input.nextInt();
System.out.println("Enter value4: ");
value4 = input.nextInt();
System.out.println("Enter value5: ");
value5 = input.nextFloat();
try
{
String insert = "INSERT INTO myDatabase"
+ " VALUES(value1,value2,value3,value4,value5)";
statement.executeUpdate(insert);
}
catch(SQLException e)
{
System.out.println("* Cannot execute query! *");
e.printStackTrace();
System.exit(1);
}
------------------------------------------------------------
So why wont the variables work when inserted into my database? i cant think of another way of doing it, any reasons why this doesnt work?
Also, in main, under addItems() it says: The method addItem(String, String, int, int, float) in the type StockAccess is not applicable for the
arguments () I dont know what arguments to pass in main where string, string etc were.