This article mainly introduces how to modify columns in Date format in mysql database. For more information, see
Import java. SQL. *; import java. text. dateFormat; // query public class SelectTable {String dbDriver = "com. mysql. jdbc. driver "; String dbUrl =" jdbc: mysql: // localhost: 3306/sss "; // String username =" root "; String password =" 123 "based on actual conditions "; public Connection getConn () {Connection conn = null; try {Class. forName (dbDriver);} catch (ClassNotFoundException e) {e. printStackTrace ();} try {conn = DriverManager. getC Onnection (dbUrl, username, password); // note that there are three parameters} catch (SQLException e) {e. printStackTrace () ;}return conn;} public void select () {Connection conn = getConn (); try {Statement stmt = conn. createStatement (); // create the Statement object System. out. println ("successfully connected to the database! "); String SQL =" select * from jdbc "; // The SQL ResultSet rs = stmt.exe cuteQuery (SQL) to be executed; // create the data object System. out. println ("id" + "\ t" + "name" + "\ t" + "brithday"); while (rs. next () {System. out. print (rs. getInt (1) + "\ t"); System. out. print (rs. getString (2) + "\ t"); System. out. print (rs. getDate (3) + "\ t"); System. out. println () ;}} catch (Exception e) {e. printStackTrace () ;}} public void insert () {Connection conn = getCo Nn (); try {Statement stmt = conn. createStatement (); System. out. println ("connected to the database successfully! "); String SQL =" insert into jdbc (id, name, birthday) values (?,?,?) "; PreparedStatement pst = conn. prepareStatement (SQL); DateFormat df = DateFormat. getDateInstance (); java. util. date dd = df. parse ("2000-12-12"); // converts the time in YYYY-MM-DD format to datelong t = dd. getTime (); java. SQL. date date = new java. SQL. date (t); pst. setInt (1, 5); pst. setString (2, "limazhi"); pst. setDate (3, date00000000pst.exe cuteUpdate (); select ();} catch (Exception e) {e. printStackTrace () ;}} public static void main (String args []) {SelectTable st = new SelectTable (); st. insert ();}}