连接到mysql数据库

时间:2016-06-30 13:13:31

标签: java mysql

我无法使用下面的代码连接到我的数据库。当我运行它时,它会给出错误“无连接”,这是我输入的错误,以防我无法连接到我的数据库,在这种情况下bball ... connect bball = new connect();是我用来调用这个连接类但拒绝它的代码。

package trustproject;

//import connectionSql.*;
import java.net.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.proteanit.sql.DbUtils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class connect {
    public Connection con;
    public PreparedStatement stat;
    public ResultSet res;


    public connect(){
    systemConnection();
    }

    public void systemConnection(){
    try {
        Class.forName("com.mysql.jdbc.Driver");
       con =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bball", "root", "admin");
       stat = (PreparedStatement) con.createStatement();
    JOptionPane.showMessageDialog(null, "Successful Connection to database");

    } catch(Exception e){
        JOptionPane.showMessageDialog(null, "No Connection");
    }

    }

    PreparedStatement prepareStatement(String insert_into_players_Name_Surname_IDNum_Position_Team) {
        throw new UnsupportedOperationException("ERROR"); //To change body of generated methods, choose Tools | Templates.
    }

}

0 个答案:

没有答案