0

[enter image description here][1]while installing mysql on pc, i got an error message that "port 3306 is currently in use. provide another port" so i changed the port number to 3305. now i am trying to connect java project in netbeans ide to mysql, but it ain't working even though i tried with both the port numbers.

enter code here

   String pword= password.getText();
   String name= tf.getText();
   String str= null;
   Statement stmt= null;
   ResultSet rs= null;
    Connection conn=null;
   try{
       Class.forName("java.sql.Driver");
       String pwd= "mysql";
       String uid="root";
       String url="jdbc:mysql://localhost:3306/project";
       try{
            conn= (Connection)DriverManager.getConnection(url,uid,pwd);
            stmt= conn.createStatement();
            String sql= "SELECT * FROM login WHERE name='" + name+ "'";
            rs= stmt.executeQuery(sql);
            rs.next();
            str= rs.getString("password");
            if(str.equals(pword))
            {
             menu m= new menu();
             m.setVisible(true);
             this.setVisible(false);

            }
            else
               JOptionPane.showMessageDialog(null, "Incorrect username or password!");
            rs.close();
            stmt.close();
            conn.close();
          }
       catch(Exception e)
       {
           JOptionPane.showMessageDialog(null, "Incorrect username or password!");
       }

   } 
   catch(Exception e)
   {
       JOptionPane.showMessageDialog(null, "Error in Connectivity");
   }
2
  • 1
    Please add exception stack trace Commented Sep 12, 2017 at 17:58
  • what errors are you getting? Was your mysql installation successful? Commented Sep 12, 2017 at 18:59

1 Answer 1

1

I did something like this (for MS SQL server) recently however I don't think you specified the database name

`String url ="jdbc:sqlserver://YourPCname\\instancename;databaseName=yourDBname";` 

(note you'd need to change "sqlserver" to "mysql")

Also make sure that your server is running.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.