Mysql database modification method for adding a Date format column _ MySQL

Source: Internet
Author: User
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 ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.