从Arduino执行MySQL查询时出错

时间:2015-03-20 14:55:03

标签: mysql sql arduino

我使用以下代码:

void setup() {
   mySerial = new Serial( this, "COM8", 115200 );
   output = createWriter( "data.txt" );
   msql = new MySQL( this, "localhost", "arduino", "root","" );
   if ( msql.connect() )
    {output.println("connected");}
    else{output.println("not connected");}
  // output = open( "data.txt" );
}
void draw() {
    if (mySerial.available() > 0 ) {
      int d = day();
      int m = month();
      int y = year();

      int s = second();  // Values from 0 - 59
      int min = minute();  // Values from 0 - 59
      int h = hour();

      String a = String.valueOf(d);
      String b = String.valueOf(m);
      String c = String.valueOf(y);
         String value = mySerial.readString();
         if ( value != null ) {
              output.print( value );
              String state=value;
              String x=a+"/"+b+"/"+c;
              String z=h+":"+min+":"+s;
              output.println(x);
              output.println(z);
              msql.execute( "INSERT INTO info(status,date,time) VALUES ("+state+","+x+","+z+");" );

         }
    }

但收到此错误:

  

错误:使用驱动程序com.mysql.jdbc.Driver 3.1 SQL.query():   java.sql.SQLException中。

     

INSERT INTO info(状态,日期,时间)VALUES(无检测   ,20/3 / 2015,20:7:23); java.sql.SQLException:你的错误   SQL语法;查看与MySQL服务器对应的手册   正确使用语法的版本' detect,20/3 / 2015,20:7:23)'   在第1行

如何解决这个问题?

0 个答案:

没有答案