2

I am using Database toolbox of Matlab to run my MySQL queries. I am doing this by using JDBC driver (Connector/J).

I am able to connect/create/delete new tables for a given database.

Is there a way by which I can directly create a new database from Matlab itself? I'm looking for a solution which lets me do this by using the toolbox or by using Java from Matlab.

4
  • Yes, you can create new database from Java application itself. For example, if you use Derby database. But, I think you can't programaticaly create database when it comes to MySQL. Commented Aug 7, 2013 at 11:26
  • If you can run plain SQL commands using your toolbox, you could try create database dbname. If your toolbox supports dynamic JDBC-URLs to connect to databases not known at compile-time, you could try that way. Commented Aug 7, 2013 at 11:30
  • I think, we can create database using PHP and Python programaticaly Commented Aug 7, 2013 at 11:30
  • Actualy, my bad. Seems you can create MySQL database programaticaly. Have a look at this question Commented Aug 7, 2013 at 11:31

1 Answer 1

3

Here's what I have used. In Matlab this works.

import java.sql.*;

ConnD = DriverManager.getConnection(...
'jdbc:mysql://localhost/?user=urname&password=urpassword');

sD=ConnD.createStatement();
Result=sD.executeUpdate('CREATE DATABASE urdatabasename');
sD.close();
ConnD.close();

Mind you, this doesn't include error handling and checks. Make sure you handle your data carefully.

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

1 Comment

Is it can be used directly in matlab? Do I need to do anything else for importing java.sql?

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.