• eclipse java 连接mysql


    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.*;
    import com.mysql.jdbc.Connection;

    public class MySql {
        public static void main(String[]args) throws SQLException {
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String url="jdbc:mysql://localhost:3306/mysql";
            String username="root";
            String password="root";
             
            Connection con=(Connection) DriverManager.getConnection(url,username,password);
            if(con!=null) {
             
                System.out.println("成功");
          }
            Statement stmt;
            ResultSet res;
            stmt=con.createStatement();
            res=stmt.executeQuery("select *from user");
            while(res.next()){
                String name=res.getString("User");
                System.out.println(name);
            }
            res.close();
        }

    }

  • 相关阅读:
    遗传算法求解旅行商(TSP)问题 -- python
    office 小技巧
    oracle创建dblink
    c# equals与==的区别
    两人之间的一些参数
    .net 枚举(Enum)使用总结
    SQL Server 日期的加减函数: DATEDIFF DATEADD
    jquery操作select
    AS3帮助手册
    Razor和HtmlHelper的使用意义
  • 原文地址:https://www.cnblogs.com/dlutxm/p/2143442.html
Copyright © 2020-2023  润新知