7

I am trying to connect MySQL database in Netbeans and stuck at the very first step- connecting the database. My Database is working fine on the console - tried command mysqladmin -u root -p ping and it says mysql id is alive. I have even created database from console. Now when i register it in Netbeans

Server Host Name:localhost 
Server Port:3306 
Admin user : root 
Admin password :<the password which works on console> 

and Admin Properties:

Path to admin tool: C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqladmin.exe 
Argument : <blank> 
Path to start command:C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe 
Argument : --console <as suggested in http://forums.netbeans.org/topic12767.html>
Path to stop command:C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqladmin.exe
Argument : -u root shutdown  

but i still get message:- "MySQL Server at localhost:3306 [root] (disconnected)"

if i right click and select "start" or "connect" i get the message in taskbar - Waiting for MYSQL Server to start... for an infinite time.

Any help what am i doing wrong here???

user3706280
  • 95
  • 2
  • 2
  • 6
  • I guess you are following this tutorial https://netbeans.org/kb/docs/ide/mysql.html,but you don't need the admin properties. Just go to the services panel--> database: right click -->add a new connection. Then just follow the dialogs.. – LMG Jun 06 '14 at 12:53
  • ok i tried that ....database->right click->create new connection-> Connector:MYSQL (Connector/J Driver)->specify database user name and password ->Test Connection and this is what i get: "Cannot Establish a connection to jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehaviour=convertToNull using com.mysql.jdbc.Driver (org/aspectj/lang/Signature)" – user3706280 Jun 07 '14 at 08:50
  • I'm going to elaborate an answer as far as I get to my desk.. You will have a suggestion soon.. Be patient.. – LMG Jun 07 '14 at 10:01
  • just as a test remove the `l?zeroDateTimeBehaviour=convertToNull ` and try again, other wise you can see the whole procedure in the answer.. – LMG Jun 07 '14 at 10:48

8 Answers8

9

Follow these 2 steps:

STEP 1 :

Follow these steps using the Services Tab:

  1. Right click on Database
  2. Create new Connection

Customize the New COnnection as follows:

  1. Connector Name: MYSQL (Connector/J Driver)
  2. Host: localhost
  3. Port: 3306
  4. Database: mysql ( mysql is the default or enter your database name)
  5. Username: enter your database username
  6. Password: enter your database password
  7. JDBC URL: jdbc:mysql://localhost:3306/mysql
  8. CLick Finish button

NB: DELETE the ?zeroDateTimeBehaviour=convertToNull part in the URL. Instead of mysql in the URL, you should see your database name)


STEP 2 :

  1. Right click on MySQL Server at localhost:3306:[username](...)
  2. Select Properties... from the shortcut menu

In the "MySQL Server Properties" dialog select the "Admin Properties" tab Enter the following in the textboxes specified:

For Linux users :

  1. Path to start command: /usr/bin/mysql
  2. Arguments: /etc/init.d/mysql start
  3. Path to Stop command: /usr/bin/mysql
  4. Arguments: /etc/init.d/mysql stop

For MS Windows users :

NOTE: Optional:

In the Path/URL to admin tool field, type or browse to the location of your MySQL Administration application such as the MySQL Admin Tool, PhpMyAdmin, or other web-based administration tools.

Note: mysqladmin is the MySQL admin tool found in the bin folder of the MySQL installation directory. It is a command-line tool and not ideal for use with the IDE.

Citations:
https://netbeans.org/kb/docs/ide/mysql.html?print=yes
http://javawebaction.blogspot.com/2013/04/how-to-register-mysql-database-server.html


We will use MySQL Workbench in this example. Please use the path of your installation if you have MySQL workbench and the path to MySQL.

  1. Path/URL to admin tool: C:\Program Files\MySQL\MySQL Workbench CE 5.2.47\MySQLWorkbench.exe
  2. Arguments: (Leave blank)
  3. Path to start command: C:\mysql\bin\mysqld (OR C:\mysql\bin\mysqld.exe)
  4. Arguments: (Leave blank)
  5. Path to Stop command: C:\mysql\bin\mysqladmin (OR C:\mysql\bin\mysqladmin.exe )
  6. Arguments: -u root shutdown (Try -u root stop)

Possible exampes of MySQL bin folder locations for Windows Users:

  • C:\mysql\bin
  • C:\Program Files\MySQL\MySQL Server 5.1\bin\
  • Installation Folder: ~\xampp\mysql\bin
Community
  • 1
  • 1
ColinWa
  • 919
  • 1
  • 10
  • 27
3

Fist of all make sure your SQL server is running. Actually I'm working on windows and I have installed a nice tool which is called MySQL workbench (you can find it here for almost any platform ).

you can see the server is running

Thus I just create a new database to test the connection, let's call it stackoverflow, with one table called user.

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

DROP SCHEMA IF EXISTS `stackoverflow` ;
CREATE SCHEMA IF NOT EXISTS `stackoverflow` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `stackoverflow` ;

-- -----------------------------------------------------
-- Table `stackoverflow`.`user`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `stackoverflow`.`user` ;

CREATE TABLE IF NOT EXISTS `stackoverflow`.`user` (
  `iduser` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(75) NOT NULL,
  `email` VARCHAR(150) NOT NULL,
  PRIMARY KEY (`iduser`),
  UNIQUE INDEX `iduser_UNIQUE` (`iduser` ASC),
  UNIQUE INDEX `email_UNIQUE` (`email` ASC))
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

You can reduce important part to

 CREATE SCHEMA IF NOT EXISTS `stackoverflow`

 CREATE TABLE IF NOT EXISTS `stackoverflow`.`user` (
      `iduser` INT NOT NULL AUTO_INCREMENT,
      `name` VARCHAR(75) NOT NULL,
      `email` VARCHAR(150) NOT NULL,
      PRIMARY KEY (`iduser`),
      UNIQUE INDEX `iduser_UNIQUE` (`iduser` ASC),
      UNIQUE INDEX `email_UNIQUE` (`email` ASC))

So now I have my brand new stackoverflow database. Let's connect to it throught Netbeans. Launch netbeans and go to the services panel list of connections available Now right click on databases: new connection.. Choose MySql connector, they already come packed with netbeans. connector Then fill in the gaps the data you need. As shown in the picture add the database name and remove from the connection url the optional parameters as l?zeroDateTimeBehaviour=convertToNull . Use the right user name and password and test the connection. data

As you can see connection is successful.

Click FINISH.

You will have your connection successfully working and available under the services.

finish

LMG
  • 966
  • 1
  • 12
  • 28
  • i cant post my pictures here so i am doing it in the answer section – user3706280 Jun 07 '14 at 11:13
  • seems i need more repo point to do that so i cont. here.... I tried the exact steps as in your pics, i created a database -"emp" as below: mysql> select * from emp; ERROR 1146 (42S02): Table 'emp.emp' doesn't exist mysql> select * from employees; +-------+------------+ | ID | NAME | +-------+------------+ | A3014 | Rehman Ali | | A3015 | Robert B | | A3103 | Tim Roger | | A3105 | Phill Frnk | +-------+------------+ 4 rows in set (0.06 sec) mysql> exit Bye C:\Users\smriti.khemani> – user3706280 Jun 07 '14 at 11:18
  • so then i created a new connection. I used database as "emp" and also tried with "mysql" still i get the same error ---- "Cannot Establish a connection to jdbc:mysql://localhost:3306/mysql using com.mysql.jdbc.Driver (org/aspectj/lang/Signature)" -i am going crazy here ...any other suggestion, is it that i need to set any environment variable or anything ..... – user3706280 Jun 07 '14 at 11:27
  • so you have a database called "emp" . Put it in the Database field in the last form. put user name and password. By the way of course you can not do select * from emp because emp is a schema and not a table. You have a lot of confusion with SQL grammar.. – LMG Jun 07 '14 at 12:44
  • okay yeah dat was a mistake... i did try putting emp in the database field and user name and password for mysql but it is just not working – user3706280 Jun 08 '14 at 04:16
  • what does the jdbc url look like? is the server running? can you connect to the database via the command line? or another tool (like mysql workbench)? – LMG Jun 08 '14 at 08:20
  • No, the server is not running in NetBeans as i see under node databases -MYSQL Server at localhost:3036 [root] (Disconnected) . This is my JDBC URL- jdbc:mysql://localhost:3306/mysql. Yes I am able to connect to my Database both from Command line as well as from MySQL Workbench – user3706280 Jun 09 '14 at 04:30
  • Then you must be able to connect also via netbeans. Of course you won't see it running from netbeans.. Are you behind a proxy? I have no other clues.. – LMG Jun 09 '14 at 10:10
2

check the context.xml file in Web Pages -> META-INF, the username="user" must be the same as the database user, in my case was root, that solved the connection error

Hope helps

LuFFy
  • 8,799
  • 10
  • 41
  • 59
Erik
  • 21
  • 1
2

I just had the same issue with Netbeans 8.2 and trying to connect to mySQL server on a Mac OS machine. The only thing that worked for me was to add the following to the url of the connection string: &serverTimezone=UTC (or if you are connecting via Hibernate.cfg.xml then escape the & as &) Not surprisingly I found the solution on this stack overflow post also:

MySQL JDBC Driver 5.1.33 - Time Zone Issue

Best Regards, Claudio

0

in my cases, i found my password in glassfish-recources.xml under WEB-INF

user7288944
  • 91
  • 2
  • 6
0
  1. Close NetBeans.

  2. Stop MySQL Server.

  3. Update MySQL (if available)

  4. Start MySQL Server.

  5. Open NetBeans.

If still doesn't connect, download MySQL Connector/J and add mysql-connector-java-[version].jar to your classpath and also to your Webserver's lib directory. For instance, Tomcat lib path in XAMPP is
C:\xampp\tomcat\lib.
Then repeat the steps again.

Community
  • 1
  • 1
Iman Ravakhah
  • 111
  • 1
  • 2
  • 5
0
  1. Download XAMPP
  2. Run XAMPP server. Click on Start button in front of MY SQL. Now you can see that color is changed to green. Now, Click on Admin.The new browser window will be open. Copy the link from browser and paste to the Admin properties as shown in below. Set path in the admin properties of database connection. Click on OK. Now your database is connected. enter image description here
0
NETBEANS 
koneksi 
dbmSET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 4
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Feb 14 '23 at 07:11