- 部分示例代码:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.time.LocalDate;
public class SQLTest {
public static void main(String[] args) {
- Connection conn = DriverManager.getConnection(url, user, password);
String sql = "INSERT INTO PUBLICATION VALUES(?,?,?)";
LocalDate pubDate = LocalDate.now();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, 100);
pstmt.setString(2, "title");
-
pstmt.setDate(3, java.sql.Date.valueOf(pubDate));
pstmt.executeUpdate();
}
}
Java 怎么将日期插入数据库
最新推荐文章于 2022-05-09 15:17:00 发布