connection = ConnectionUtils.getConnection();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
String dateValue = simpleDateFormat.format(now);
sql = "insert into news_base(fid,title,date,author) values("+fid+",'"+title+"','"+dateValue+"','Admin')";
statement = connection.createStatement();
statement.executeUpdate(sql);
sql1 = "insert into news_content (cid,fid,content) values("+cid+","+fid+",'"+content+"')";
statement1 = connection.createStatement();
statement1.executeUpdate(sql1);
' news_base'的ID是主键和自动增量。 ' news_base'的ID表是针对cid的' news_content'表
答案 0 :(得分:1)
你可以试试这个: -
在statement.executeUpdate(sql);
添加此之后
ResultSet rs = statement.getGeneratedKeys();
if(rs.next())
{
int your_id = rs.getInt(1);
}