通過java查看mysql表中字段內(nèi)容。
package org.example.day11.dao; import java.sql.*; public class JDBCTest { public static void main(String[] args){ String url = "jdbc:mysql://localhost:3306/splunkdb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"; String user = "root"; String password="1234..com"; Connection conn=null; try{ conn=DriverManager.getConnection(url,user,password); String sql="select * from employee5 ;"; PreparedStatement ps=conn.prepareStatement(sql); ResultSet rs=ps.executeQuery(); while (rs.next()){ System.out.println(rs.getString("id")); System.out.println(rs.getString("name")); System.out.println(rs.getBoolean("sex")); System.out.println(rs.getDate("birthday")); System.out.println(rs.getDouble("salary")); System.out.println(rs.getDate("entry_date")); System.out.println(rs.getString("resume")); } rs.close(); ps.close(); } catch(SQLException e){ e.printStackTrace(); }finally{ if(conn!=null){ try { conn.close(); }catch (SQLException e){ e.printStackTrace(); } } } } } |
|