|
-
Jan 17th, 2008, 05:49 PM
#1
Thread Starter
Member
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);
}
-
Jan 17th, 2008, 06:27 PM
#2
Re: inserting data into Microsoft database
And the Microsoft database would be... Microsoft Access or MS-SQL Server exactly!
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 17th, 2008, 10:17 PM
#3
Thread Starter
Member
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
-
Jan 18th, 2008, 06:18 AM
#4
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();
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 18th, 2008, 07:04 AM
#5
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?
-
Jan 19th, 2008, 08:07 PM
#6
Thread Starter
Member
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();
}
}
-
Jan 19th, 2008, 08:29 PM
#7
Re: inserting data into Microsoft database
That is not the syntax for INSERT.
Have you ever done an INSERT that worked before?
-
Jan 19th, 2008, 08:56 PM
#8
Thread Starter
Member
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 + "')";
-
Jan 19th, 2008, 09:04 PM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|