SachinFederer
SachinFederer

Reputation: 41

How to import an existing database into netbeans

I had created a database using mysql workbench and i saved that database in one of the local drives. So in netbeans I need to design a database which is same as the earlier (created by using mysql workbench). So I would like to import that database into netbeans. Can anyone explain the procedure to do so?

Upvotes: 3

Views: 10997

Answers (2)

Justin Duncan
Justin Duncan

Reputation: 88

You can use the built-in tools.

  • With your NetBeans project up, click new file and search for a persistence unit.
  • Follow the prompts entering the corresponding information(ie, host info, username, password, etc).
  • Once completed, go back in your project view and click on the services tab. You should see the database connection there.
  • To add them to your project, go back to your project tab and add a new file of type "Entities Classes from Database" the next prompts will ask you what tables to import and such.
  • Once completed, NetBeans will auto import all tables with getters and setters.

Here is a succinct example from Official Documentation: https://platform.netbeans.org/tutorials/nbm-crud.html#creating-app

Upvotes: 0

Kashyap Kotak
Kashyap Kotak

Reputation: 1938

A couple of days back I faced the same problem and found a easy solution. Though this question is asked 2 years back, I am posting this answer because it still doesn't have an answer here, so that it can provide help to other people with same problem in future.


I assume you know how to configure MySQL server. If no, visit https://netbeans.org/kb/docs/ide/mysql.html and follow the 'Configuring MySQL Server Properties' part.
After you create the server, right click on the 'MySQL Server'->'Create new database'. Give the database same name as the existing database has.
Now create a connection to the newly created database. If you dont know how, see the 'Starting the MySQL Server' and 'Creating and Connecting to the Database Instance' from https://netbeans.org/kb/docs/ide/mysql.html.
Now Expand the newly created connection which will look like 'jdbc:mysql://localhost:(portNumber)/(databaseName)'. Expand the database name node and right click 'table' and select 'Execute Command'
A new window will open. Assuming that you have a .sql file(Or may be a file without extension but consisting of SQL commands. You can export the database in file using your current admin tool if you have not already). Open that file in editor(notepad) and copy paste everything in the new opened command window in Netbeans.
Before Executing, just add one line before which states which database to use to execute query on.

USE <newly_created_database_name>;

as shown in the screenshot below (Red mark), it should be before the first line of the copy pasted SQL commands.
enter image description here
Now Execute the commands using the 'run SQL' button (green mark in image). To check, expand the tables node to see all the tables in original database are created. Now you have your original database in place to work with.

Upvotes: 2

Related Questions