mysql数据库——时间类型

-- DATA(三个字节1000-1-01-01~9999-12-31),YYYY-MM-DD
-- TIME,()HH:MM:SS
-- YEAR,(1901-2155)YYYY
-- DATETIME,(1000-1-01-01~9999-12-31)YYYY-MM-DD HH:MM:SS 还可以继续向下精确
-- TIMRSTAMP(1970-01-01~2037-xx-xx)YYYY-MM-DD HH:MM:SS
-- 
create table tabledate (birthday date);

select * from tabledate;

insert into tabledate values('2018-06-28',20150201,20150201);
-- 插入格式多样(非字符串格式)

alter table tabledate add datetimecol datetime;
alter table tabledate add datetimecol2 datetime(2);
-- 括号带数字表示精确度,表示秒还可以继续向下面增加

alter table tabledate add time1 timestamp;-- now时间
alter table tabledate add time2 timestamp;-- 00:00:00时间

alter table tabledate drop time1;
alter table tabledate drop time2;





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会尽量回答你的问题。关于Java连接MySQL数据库实现登录注册功能,以下是一个简单的实现步骤: 1.下载并安装MySQL数据库,安装完成后,创建一个名为“test”的数据库。 2.下载并安装JDBC驱动程序,将下载的JDBC驱动程序的jar包添加到项目的classpath中。 3.编写Java代码,实例化JDBC驱动程序,连接MySQL数据库,创建用户表,实现用户的注册和登录功能。 以下是一个简单的Java代码示例: ``` import java.sql.*; public class JdbcTest { public static void main(String[] args) { // 数据库连接信息 String url = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC"; String username = "root"; String password = "123456"; // 注册JDBC驱动程序 try { Class.forName("com.mysql.cj.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("找不到JDBC驱动程序!"); e.printStackTrace(); return; } // 连接MySQL数据库 Connection conn = null; try { conn = DriverManager.getConnection(url, username, password); } catch (SQLException e) { System.out.println("连接MySQL数据库失败!"); e.printStackTrace(); return; } // 创建用户表 Statement stmt = null; try { stmt = conn.createStatement(); String sql = "create table if not exists user(id int primary key auto_increment, username varchar(50) not null, password varchar(50) not null)"; stmt.executeUpdate(sql); } catch (SQLException e) { System.out.println("创建用户表失败!"); e.printStackTrace(); return; } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } // 用户注册 PreparedStatement pstmt = null; try { String sql = "insert into user(username, password) values (?, ?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, "user1"); pstmt.setString(2, "123456"); pstmt.executeUpdate(); } catch (SQLException e) { System.out.println("用户注册失败!"); e.printStackTrace(); return; } finally { if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } // 用户登录 ResultSet rs = null; try { String sql = "select * from user where username=? and password=?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, "user1"); pstmt.setString(2, "123456"); rs = pstmt.executeQuery(); if (rs.next()) { System.out.println("用户登录成功!"); } else { System.out.println("用户名或密码错误!"); } } catch (SQLException e) { System.out.println("用户登录失败!"); e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } // 关闭数据库连接 try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } ``` 在上面的代码中,我们先注册了JDBC驱动程序,然后连接了MySQL数据库,接着创建了一个名为“user”的用户表,实现了用户的注册和登录功能。你可以根据自己的需求修改代码中的数据库连接信息和SQL语句。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值