• 连接数据库查询数据


    package dao;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    public class Test {
    private String className="A";
    private String url="B";
    private String user="C";
    private String password="D";
    private Connection connection;
    private Statement statement;
    private ResultSet resultSet;

    public Connection getConn() {
    try {
    Class.forName(className);
    connection = DriverManager.getConnection(url, user, password);
    } catch (ClassNotFoundException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    return connection;
    }

    public ResultSet executeQuery(String sql) {
    connection=getConn();
    try {
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);
    } catch (SQLException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    return resultSet;
    }

    public static void main(String[] args) {
    Test test = new Test();
    ResultSet set = test.executeQuery("select * from T");
    }
    }
  • 相关阅读:
    button theme
    Container详解
    flutter控件之ExpansionPanelList
    flutter屏幕适配
    Flutter 获取控件尺寸和位置
    Dart
    异步async、await和Future的使用技巧
    flutter key
    Flutter 控件之 Routes 和 Navigator. [PopupRoute]
    flutter
  • 原文地址:https://www.cnblogs.com/GodZhe/p/4842473.html
Copyright © 2020-2023  润新知