# Connect Procssing with Database

**URL:** <https://discourse.processing.org/t/connect-procssing-with-database/9563>\
**Category:** Libraries\
**Created:** [March 24, 2019, 4:02am UTC](https://discourse.processing.org/t/connect-procssing-with-database/9563 "2019-03-24T04:02:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ismaiel\_Ahmed](https://avatars.discourse-cdn.com/v4/letter/i/da6949/32.png) [@Ismaiel\_Ahmed](https://discourse.processing.org/u/Ismaiel_Ahmed)\
**Post date:** [March 24, 2019, 4:02am UTC](https://discourse.processing.org/t/connect-procssing-with-database/9563/1 "2019-03-24T04:02:38Z")

</div>

Hello everyone,  
I’ve read that i can normally use java code with processing code in one program.  
I created the following class to connect to MYSQL online server “which i created online”

```auto
import java.sql.*;
class Database
  {    
    void Database () 
      {        
      }
    void createDatabase ()
      {
        try
          {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection ("jdbc:mysql://remotemysql.com:3306/gPQbxUed4a","gPQbxUed4a"," ********");
            Statement stmt = con.createStatement();
            stmt.executeQuery("use gPQbxUed4a;");
            stmt.executeQuery("create table emp(id int(10),name varchar(40),age int(3));");
            con.close();
          }
         catch (Exception e)
          {
            System.out.println(e);
          }
      }
  }

```

in the main sheet i create instance of the database and run createDatabase method

```auto
Database myDatabase = new Database();
 myDatabase.createDatabase();

```

after running the code a table should be created in my database. However, I’m checking the database and nothing is happeneed

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [March 24, 2019, 5:57am UTC](https://discourse.processing.org/t/connect-procssing-with-database/9563/2 "2019-03-24T05:57:54Z")

</div>

Could you provide all the code, including the Processing code? The code you provided defines the class. You need to show the lines where the class is instantiated. I would recommend to work in a local environment before you attempt to connect to a server. It will be easier to debug your code.

You should consider checking the DB Manager tool and see if it works for you: [https://forum.processing.org/two/discussion/21440/db-manager-for-processing](https://forum.processing.org/two/discussion/21440/db-manager-for-processing)

Kf

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 24, 2019, 8:42am UTC](https://discourse.processing.org/t/connect-procssing-with-database/9563/3 "2019-03-24T08:42:59Z")

</div>

> [@Ismaiel\_Ahmed](#):
>
> void Database ()

This looks wrong

The constructor is without void

---

<div class="post-metadata">

**Author:** ![Ismaiel\_Ahmed](https://avatars.discourse-cdn.com/v4/letter/i/da6949/32.png) [@Ismaiel\_Ahmed](https://discourse.processing.org/u/Ismaiel_Ahmed)\
**Post date:** [March 24, 2019, 9:33am UTC](https://discourse.processing.org/t/connect-procssing-with-database/9563/4 "2019-03-24T09:33:58Z")

</div>

Here is the code

```auto
Database myDatabase = new Database();

void setup()
{
  myDatabase.createDatabase();
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 25, 2019, 9:16pm UTC](https://discourse.processing.org/t/connect-procssing-with-database/9563/5 "2019-03-25T21:16:13Z")

</div>

You might be interested in the SQL Library for Processing.

> **[GitHub - fjenett/sql-library-processing: SQLibrary – a SQL database library...](https://github.com/fjenett/sql-library-processing)**
>
> SQLibrary – a SQL database library for Processing incl. MySQL, SQLite and PostgreSQL - GitHub - fjenett/sql-library-processing: SQLibrary – a SQL database library for Processing incl. MySQL, SQLite...

There are also interesting example sketches connected with the DB Manager for Processing (mentioned earlier):

- [https://forum.processing.org/two/discussion/21440/db-manager-for-processing](https://forum.processing.org/two/discussion/21440/db-manager-for-processing)
- [GitHub - vesolba/DBManager-for-Processing: Java DB Manager for Processing](https://github.com/vesolba/DBManager-for-Processing)
- [GitHub - vesolba/DBM4Processing-Examples: Examples of how to use Derby with Processing.](https://github.com/vesolba/DBM4Processing-Examples)

Also see:

> [@Accessing an SQL server database using the SQL library](https://discourse.processing.org/t/accessing-an-sql-server-database-using-the-sql-library/876/5):
>
> @miasoft Why did you try? I good place to start would be [this](https://stackoverflow.com/questions/2451892/how-do-i-connect-to-a-sql-server-2008-database-using-jdbc) I have tested creating and reading an MySQL using Processing. For MSSQL, you will need to setup the environment which I don’t have atm. Kf
