Reputation: 127
st.executeUpdate("insert into groupperformance (Date,Gid,GName) values('"+yourDate+"',select Gid,GroupName from grouping)");
I use the above query for insert table values.In this table variable yourDate having the Current system Date.And I copy the data's from the table grouping.With out yourDate variable query works fine and inserting values from grouping table to groupperformance table.What can I do for insert current date as default value.
Upvotes: 2
Views: 964
Reputation: 23992
st.executeUpdate(
"insert into groupperformance (Date,Gid,GName)
select '" + yourDate + "', Gid,GroupName from grouping"
);
But, make sure that yourDate
string is in valid MySQL date format YYYY-MM-DD
.
And, if you want to insert current date from the database server, you can use now()
or curdate()
instead of your selected date.
st.executeUpdate(
"insert into groupperformance (Date,Gid,GName)
select curdate(), Gid,GroupName from grouping"
);
Upvotes: 0
Reputation: 44844
In mysql you can use now()
to add the current date in the table
Here is an example how its done
http://sqlfiddle.com/#!2/080d7f
Upvotes: 0
Reputation: 7447
You can use mysql's NOW()
function:
st.executeUpdate("insert into groupperformance (Date,Gid,GName) values(NOW(),select Gid,GroupName from grouping)");
Upvotes: 0
Reputation: 7288
You can use SELECT GETDATE() AS CurrentDateTime
, which will return 2008-11-11 12:45:34.243
OR something like this:
CREATE TABLE Orders
(
OrderId int NOT NULL PRIMARY KEY,
ProductName varchar(50) NOT NULL,
OrderDate datetime NOT NULL DEFAULT GETDATE()
)
Upvotes: 1