首页 > 数据库技术 > 详细

mysql jdbc操作

时间:2019-01-13 00:52:47      阅读:145      评论:0      收藏:0      [点我收藏+]
import java.sql.*;
import java.util.Map;

public class Mysql {
    public static void main(String[] args) {
        Connection conn = getConn();
        PreparedStatement pstmt;
        try {
            pstmt = conn.prepareStatement("select * from lw_area where area_id like ‘35%‘ and area_level <=3");
            ResultSet rs = pstmt.executeQuery();
            //Map<String, Map<String, Object>>  
            while (rs.next()) {
                System.out.println(rs.getLong("area_id"));
                System.out.print(rs.getLong("area_pid"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    private static Connection getConn() {
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/linewell_assets_mgt_es?serverTimezone=UTC";
        String username = "root";
        String password = "123456";
        Connection conn = null;
        try {
            Class.forName(driver); //classLoader,加载对应驱动
            conn = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}

 

mysql jdbc操作

原文:https://www.cnblogs.com/chenmz1995/p/10261501.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!