inserting data into Microsoft database
Hi everyone
Can anyone please help me to find methods, to use when clicking an button inserting data into table. Example say ageButton by clicking on it insert data into table which already exists in the database. I did use this method but does not work. Thanks a lot
Code:
public void orderProduct()
{
String sqlSelect = "INSERT INTO age" + "valuse (34,dave,short)";
System.out.println(sqlSelect);
}
Re: inserting data into Microsoft database
And the Microsoft database would be... Microsoft Access or MS-SQL Server exactly!
Re: inserting data into Microsoft database
thank you for reply, it is Microsoft Access, and i got all column the same with the SQL statements
Re: inserting data into Microsoft database
This code should be a good example
Code:
Connection con = DriverManager.getConnection( database ,"","");
Statement stmt;
stmt = con.createStatement();
String stat = ("SELECT * FROM TEMP"+" WHERE TEST_NAME = "+testName);
ResultSet rs = stmt.executeQuery(stat);
rs.next();
String a = rs.getString("TEST_NAME");
stmt.close();
con.close();
Re: inserting data into Microsoft database
Missing space after AGE
Did not spell VALUES correctly.
Need single-quotes around string values in the insert list.
Making sure that you build proper SQL syntax statements helps.
You have the WRITELINE - you are looking at the SQL statement - correct?
Re: inserting data into Microsoft database
Hi thank you for yor help,I try this code but it show that the SQL error. Could you please tell me whatis wrong
Code:
/** create the SQL insert statement using attribute values */
connection= DriverManager.getConnection( url ,"","");
Statement stmt;
statement = connection.createStatement();
String stat = ("INSERT INTO product product_anme,price ,size" + " VALUES + ('Omar','9.90','medium')");
ResultSet rs = statement.executeQuery(stat);
rs.next();
String a = rs.getString(" PRODUCT_NAME ");
statement.close();
connection.close();
} catch (Exception e)
{
System.out.println("SQL Error.");
System.out.println();
}
}
Re: inserting data into Microsoft database
That is not the syntax for INSERT.
Have you ever done an INSERT that worked before?
Re: inserting data into Microsoft database
yes,this statement
Code:
String sqlInsert = "INSERT INTO customer " + "(door_number,street_name,post_code,phone_number)" +
"VALUES ('" + door_number + "' , '" + street_name + "' , '" + post_code + "' , '" +
phone_number + "')";
Re: inserting data into Microsoft database
That's great...
So you realize now that
INSERT INTO product product_anme,price ,size values...
is missing ()'s around the field-list
INSERT INTO product (product_anme,price ,size) values...
The syntax is - to summarize
INSERT INTO {tablename} ({field1},{field2}...) values ({value1},{value2}...)
Simple things like spaces and parenthesis are important to the query parser.