Accessing an SQL server database using the SQL library

Hi, I am new to Processing and this forum. I couldn’t find any other posts on this so if this is an old question, please provide a link to the answer. Can you use the SQL library to access an SQL Server database? The library lists MySql access. If so, what modifications would be needed? Thank you.

1 Like

Are you running in the back end or are you accessing as a client? Or you want to do a get/post request? If the latter, do you have already a layer that allows you to interact with your DB?

This is next post is not a MsSQL but a java DB (Derby so I understand from the post): https://forum.processing.org/two/discussion/comment/107288/#Comment_107288 It does not answer your post but I added more for future reference.

Kf

1 Like

Thanks Kf, I am just starting this project. The goal is to use serial communications between a pc and an Arduino board. This step has been accomplished. Next step is to establish this serial communication through a bluetooth connection. I just got the HC05 so that is still to be done. Once the communication has been established, I want to also interface with a database where command codes can be stored. Commands could then be accessed through the pc and sent to the arduino. This is still in the planning stages but this would allow a user friendly remote command interface to a robot where the commands could be updated without reprogramming the arduino directly. It is ambitious and will have to be thought out in detail once the basic communication and access are established. The link you provided looks promising. Thanks again.

Hi,
I looking for MSSQL lib too. Not success! :disappointed:

@miasoft Why did you try? I good place to start would be this

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

I did accessing MSSQL exfmple. All Ok.

Here is source code for Processing

// Example from MIASOFT (www.miasoft.h1n.ru) 
// Example created on 2019-02-22 by Powder
// Tested with Processing 3.5.3 + JDK 1.8 + sqljdbc42.jar(MSSQL2008r2). Win7x32 
// my classpath for jdbc driver:  CLASSPATH=C:\sqljdbc_4.2\enu\jre8;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;

int count;
boolean keypress=false;
Connection con = null;
Statement stmt = null;
ResultSet executeQuery= null;
String JDBC_URL = "jdbc:sqlserver://tycoon\\SQL2008r2;databaseName=Abitur;user=sa;password=xxxxx;";

void setup() { 
    size(400,400);
    textSize(25);
    textAlign(CENTER);
    fill(255,0,0);
    text("Click mouse or any key", (width/2), height/2);
    textSize(15);
    text("(see result in console)", (width/2), height/2+40);
 }
 

  void draw(){
    if ( keypress == true) {
      count+=1;
      println("==========  count = "+count+"  =============");
      keypress=false;
       try {
            con = DriverManager.getConnection(JDBC_URL); 
            stmt = con.createStatement();
            executeQuery = stmt.executeQuery("SELECT * FROM DummyStr");
            // set of data and then display it.
            while (executeQuery.next()) {
                System.out.println(executeQuery.getString("Str"));  // field name "Str" (DummyStr.Str)
            }   
            // from another table 
            executeQuery = stmt.executeQuery("SELECT * FROM Lgoty");
            // set of data and then display it.
            while (executeQuery.next()) {
                System.out.println(executeQuery.getString("Shortname"));  // field name "Shortname" (Lgoty.Shortname)
            }   
      
    
  
         } catch (SQLException ex) {
           // Handle any errors that may have occurred
           println("exception:  " +ex);
         
        }
        finally {
          println("==========  close all ============");
         if (executeQuery != null) try { executeQuery.close(); } catch(Exception e) {}
         if (stmt != null) try { stmt.close(); } catch(Exception e) {}
         if (con != null) try { con.close(); } catch(Exception e) {}
      }       
    }
   }
void keyPressed() {
       keypress = !keypress;
      println(keypress);
  }

void mousePressed() {
       keypress = !keypress;
      println(keypress);
  }

1 Like