Loading...
Logo
Processing Forum
I am doing one project where I want the user to fill the data into the form( text field) and that data should be submitted to the mysql database once the user enters the data and clicks on the submit button. Can somebody suggest me which library to use to create the GUI for the entry form ( I am thinking about controlP5 for GUI and SQLibrary for database connectivity with MySQL). Please suggest me following

1. some good libraries for GUI creation (other than ControlP5) which can be used with Mysql and 
2. Is it possible to get the data entered in the text box(TextField in ControlP5 lib)  as a string and send to the database. Thanks.

Replies(6)

Interfasacia have some nice text boxes, there's a good list of the most common GUI libraries for processing here:  http://www.processing.org/reference/libraries/#libraries under the graphical interface part.

Before you start however ask yourself why your using Processing to do this, the Swing interface provides a good way of creating GUIs for database systems quickly with relative ease, combined with Netbeans you could probably code a DB system in Swing in a couple of days.

To answer your second question you can get the data entered from a text box and send it to a database using what is known as a prepared statement with the data from the text box, your probably best doing some reading up on the JDBC connector and its functionality before you start.
I am using SQLibrary for connecting to the database. I have successfully conected to the  database now I want the data to get stored in database as i put the data in  textfield. pls suggest me how to do it.
when i put the numerical values my database gets updated but when i put variables is shows error. pls help. below is the code I am using


Copy code
  1. import controlP5.*;

  2. import de.bezier.data.sql.*;

  3. ControlP5 controlP5;

  4. DatabaseManager db;
  5. MySQL msql;


  6. Data data;

  7. int buttonValue = 1;

  8. boolean isOpen = true;
  9. boolean isTrue;
  10. boolean isOk;
  11. boolean isCheck;
  12. boolean isWho, isPhone;

  13. int myColorBackground = color(0, 0, 0);

  14. String textName;
  15. String textId;

  16. String tName, tId;


  17. EntryForm entryForm;

  18. ControlFont font;

  19. controlP5.Button submit, submit1, submit2, submit3, submit4, submit5;

  20. controlP5.Button label, label1, label2, label3, label4, label5;

  21. controlP5.Button  back1, back2, back3, back4, back5;

  22. Textfield myTextfield, myTextfield1, myTextfield2, myTextfield3;


  23. CheckBox checkbox;
  24. ListBox l;
  25. PFont font1;


  26. void setup() {

  27.   size(1024, 768);
  28.   smooth();
  29.   frameRate(30);
  30.   
  31.   controlP5 = new ControlP5(this);
  32.  
  33.   PFont pfont = createFont("Arial", 12, true); // use true/false for smooth/no-smooth
  34.  
  35.   font = new ControlFont(pfont);
  36.   
  37.   font1 = createFont("Arial", 16);
  38.  
  39.   String user  = "root";
  40.   String pass  = ""; 
  41.   String database = "test";


  42.   msql = new MySQL( this, "localhost", database, user, pass );  
  43.   db = new DatabaseManager();

  44.   db.connect();

  45.   entryForm = new EntryForm();
  46.   entryForm.design();
  47.   
  48.   data = new Data();
  49.  
  50. }


  51. void draw() {

  52.   background(0);

  53.  // entryForm.check();
  54.  
  55. }

  56. public void controlEvent(ControlEvent theEvent) {
  57.  // println(theEvent.controller().id());
  58. }



  59. public void name(String theName){
  60.  println(theName); 
  61.   data.setName(theName);
  62.  
  63. }

  64. public void id(String theId){
  65.   println(theId); 
  66.   data.setId(theId);
  67. }


  68. public void next(float theValue) { 

  69.  tId = data.getId();
  70.  tName = data.getName();
  71.  db.storeData(tId, tName); 
  72. }

  73. class Data{
  74.   
  75.   public String name;
  76.   public String id;
  77.   
  78.   Data(){
  79.   }
  80.   
  81.   void setName(String textName){
  82.     name = textName;
  83.   }
  84.     
  85.   void setId(String textId){
  86.     id = textId;
  87.   }
  88.   
  89.    public String getId(){
  90.     return id;
  91.   }
  92.   
  93.   public String getName(){
  94.     return name;
  95.   } 
  96.     
  97. }

  98. import java.sql.*;

  99. class DatabaseManager{
  100.   
  101.  // public java.sql.Connection con;
  102.  //  public java.sql.Statement st;  
  103.   
  104.   DatabaseManager(){
  105.   }
  106.        
  107.   void connect(){
  108.    
  109.    if ( msql.connect() )
  110.     {
  111.         msql.query( "SELECT COUNT(*) FROM guest" );
  112.         msql.next();
  113.         println( "number of rows: " + msql.getInt(1) );
  114.     }
  115.     else
  116.     { 
  117.         println("connection failed !");
  118.     }
  119.   }  
  120.   
  121.  
  122.   void storeData(String id, String name){
  123.     
  124.       
  125.       if ( msql.connect() )
  126.       {
  127.          msql.execute("INSERT INTO guest(guest_id, name) VALUES ( "+id+" , "+name+")");
  128.          println(id);
  129.          println(name);
  130.          println("database updated!!!");
  131.       }
  132.   }
  133. }



  134. class EntryForm {

  135.   EntryForm() {
  136.   }


  137.   void design() {


  138.     label = controlP5.addButton("Visitor Name", 200, 150, 100, 150, 30);
  139.     label.setId(1);
  140.     label.captionLabel().setControlFont(font);
  141.     //label.captionLabel().setControlFontSize(1);   


  142.     myTextfield = controlP5.addTextfield("name")
  143.       .setPosition(350, 100).setSize(250, 30)
  144.         .setFont(font1)
  145.           .setFocus(true)
  146.             .setColor(color(255, 0, 0))
  147.               .setAutoClear(true).setColorCaptionLabel(255).setValueLabel("Name").setMax(50) ;  


  148.     label = controlP5.addButton("Enter Id", 200, 150, 200, 150, 30);
  149.     label.setId(3);
  150.     label.captionLabel().setControlFont(font);


  151.     myTextfield1 = controlP5.addTextfield("id")
  152.       .setPosition(350, 200).setSize(250, 30)
  153.         .setFont(font)
  154.           .setFocus(true)
  155.             .setColor(color(255, 0, 0))
  156.               .setAutoClear(true).setColorCaptionLabel(255); 



  157.     submit = controlP5.addButton("next", 0, 420, 280, 100, 25);
  158.     submit.setId(5);
  159.     submit.captionLabel().setControlFont(font);
  160.   }
  161. }
" when i put variables is shows error"
It can help if you show us as well the errors you get...
It would need to have both libraries to run your code... and to create a database similar to your!
when I put variables it shows the following error

SQL.query(): java.sql.SQLException.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'suhit' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
at de.bezier.data.sql.SQL.execute(Unknown Source)
at Guest_Entry_Appplication$DatabaseManager.storeData(Guest_Entry_Appplication.java:197)
at Guest_Entry_Appplication.next(Guest_Entry_Appplication.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
at controlP5.ControlBroadcaster.callTarget(Unknown Source)
at controlP5.ControlBroadcaster.broadcast(Unknown Source)
at controlP5.Controller.broadcast(Unknown Source)
at controlP5.Button.setValue(Unknown Source)
at controlP5.Button.activate(Unknown Source)
at controlP5.Button.mouseReleased(Unknown Source)
at controlP5.Controller.setMousePressed(Unknown Source)
at controlP5.ControllerGroup.setMousePressed(Unknown Source)
at controlP5.ControlWindow.mouseReleasedEvent(Unknown Source)
at controlP5.ControlWindow.mouseEvent(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:848)
at processing.core.PApplet.handleMouseEvent(PApplet.java:1794)
at processing.core.PApplet.dequeueMouseEvents(PApplet.java:1748)
at processing.core.PApplet.handleDraw(PApplet.java:1642)
at processing.core.PApplet.run(PApplet.java:1530)
at java.lang.Thread.run(Thread.java:680)


//this is the output...which i m printing to get the values.i dont know why it is showing null

null
suhit

database updated!!!  // this shows database is getting updated.

problem solved. actually there was the problem in the query which i written to insert the data into the database.

here is the actual query to send data in the database

Copy code
  1.   msql.execute("INSERT INTO guest(guest_id, name) VALUES ('"+id+"', '"+name+"')");