Netbeans MySQL database connection

1 Here Insert Picture Description
2 Add the driver. Here Insert Picture Description
Here Insert Picture Description
But not connected
later switched to version 8.0 drivers got only connection
Here Insert Picture Description

Here Insert Picture Description3Here Insert Picture Description
4Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description在这里插入代码片package newpackage;

/**
*

  • @author X
    /
    import java.io.
    ;
    import java.sql.*;
    import com.mysql.jdbc.Connection;
    public class JDBCTest {
    public static void main(String[] args){

    // 第一步注册驱动
    try{Class.forName(“com.mysql.jdbc.Driver”);
    //step2 connect to the DB
    String url=“jdbc:mysql://localhost:3000/web01?useUnicode=true&characterEncoding=UTF-8&useSSL=false”;
    String userName=“root”;
    String password=“root”;
    java.sql.Connection con = DriverManager.getConnection(url,userName,password);
    //step3 start Query
    Statement stmt= con.createStatement();
    ResultSet rs=stmt.executeQuery(“select * from user”);
    while(rs.next()){
    System.out.println(rs.getInt(1)+","+rs.getString(2)+","+rs.getString(3));}
    if(rs!=null) rs.close();
    if(stmt!=null) stmt.close();
    if(con!=null) con.close();
    }catch(Exception e){
    e.printStackTrace();
    }

Published 17 original articles · won praise 0 · Views 287

Guess you like

Origin blog.csdn.net/qq_41757128/article/details/104528593
Recommended