John Hogan
John Hogan

Reputation: 1036

mySQL ,sql file netbeans

How do I execute a .sql file using mysql and netbeans.

I am doing a course that requires me to interact with an .sql file that they have provided but the good guys at the Fitzwilliam institute haven't deemed it fit to explain how to use this file.

If can tell me that would be great. I have already set up the basic database using netbeans and mySql.

Thank you

Upvotes: 1

Views: 5826

Answers (3)

D-rk
D-rk

Reputation: 5919

if the sql file is too large, netbeans cannot open it. In this case you can use the tool ij (link) which comes with Derby:

Start ij commandline tool and then do something like this:

ij> connect 'jdbc:derby:MyDbTest;create=true' user 'peter' password 'parker';
ij> run 'sqlscript.sql';

Upvotes: 1

John Hogan
John Hogan

Reputation: 1036

Running an SQL Script Another way to manage table data in NetBeans IDE is by running an external SQL script directly in the IDE. If you have created an SQL script elsewhere, you can simply open it in NetBeans IDE and run it in the SQL Editor. For demonstrative purposes, download ifpwafcad.sql and save it to a location on your computer. This script creates two tables similar to what you just created above (Counselor and Subject), and immediately populates them with data. Because the script overwrites these tables if they already exist, delete the Counselor and Subject tables now so it becomes obvious that new tables are being created when the script is run. To delete tables: Right-click the Counselor and Subject table nodes in the Database Explorer and choose Delete. Click Yes in the Confirm Object Deletion dialog box. Note that the dialog box lists the tables that will be deleted. When you click Yes in the Confirm Object Deletion dialog box, the table nodes are automatically removed from the Database Explorer.

To run the SQL script on MyNewDatabase: Choose File > Open File from the IDE's main menu. In the file browser navigate to the location where you previously saved ifpwafcad.sql and click Open. The script automatically opens in the SQL Editor.

Make sure your connection to MyNewDatabase is selected from the Connection drop-down box in the toolbar at the top of the Editor.

Connection drop-down box in the SQL Editor toolbar Click the Run SQL (run SQL button) button in the SQL Editor's task bar. The script is executed against the selected database, and any feedback is generated in the Output window.

To verify changes, right-click the MyNewDatabase connection node in the Runtime window and choose Refresh.

The Refresh option updates the Database Explorer's UI component to the current status of the specified database. Note that the two new tables from the SQL script now display as a table nodes under MyNewDatabase in the Database Explorer.

Choose View Data from the right-click menu of a selected table node to see the data contained in the new tables. In this manner, you can compare the tabular data with the data contained in the SQL script to see that they match.

Upvotes: 0

MaVRoSCy
MaVRoSCy

Reputation: 17839

Ok, if you have created a connection to your MySql db, then things are pretty forward. Go to 'Services' tab, expand the Database options. Right click the connection you have created. Click 'Connect' to connect to the db. And then right click your connection and click 'Execute Command...'.

enter image description here

Write the command in the editor, and click the 'Run Sql' (Ctrl+Shift+E)

enter image description here

Upvotes: 2

Related Questions