0

Hye i dont seem to be able to connect the database for my project and i cant figure out why . i already create the database in the Mysql workbench and i still cannot run the jdbc.java

package database;

import java.awt.Component;
import java.awt.List;
import java.io.File;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.SocketImpl;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import common_interface.Honeyword;

public class JDBC {

    public static void ConnectDatabase()
    {
        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con=DriverManager.getConnection("jdbc:oracle://localhost:3306/Honeyword","root","qwertyuiop4595");
            System.out.println("Connected to Database..");
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }

    static Connection con;
nuradilla
  • 115
  • 2
  • 5
  • 15
  • Please provide more information like what is the exception you are getting?? – Ubercool Mar 04 '18 at 11:01
  • 1
    If you want to connect to a MySQL database you need to use the MySQL JDBC driver, not the Oracle JDBC driver. – Gord Thompson Mar 04 '18 at 11:13
  • Unrelated, but given your imports, your class should probably be splitted into several different classes: awt, swing, net, sql, and concurrent in the same class: yikes. Using a single static connection, not respecting the Java naming conventions, catching Exception, and ignoring exceptions are also big code smells. – JB Nizet Mar 04 '18 at 11:15

1 Answers1

0

It seem's that you work with MySQL database, and I would suggest you to use the straignt MySQL driver instead of Oracle's:

Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Honeyword","root","qwertyuiop4595");

Post an exception text please.

darth jemico
  • 605
  • 2
  • 9
  • 18