3 messages in com.mysql.lists.javaquery error in javacode
FromSent OnAttachments
Gebhardt, Karsten06 Oct 2002 22:11 
Peter T. Abplanalp07 Oct 2002 07:19 
Jasper Fontaine07 Oct 2002 07:45 
Subject:query error in javacode
From:Gebhardt, Karsten (Kars@health.wa.gov.au)
Date:10/06/2002 10:11:57 PM
List:com.mysql.lists.java

I'm using java to read from an tcp port an store the receiving data in a mysql database. This has been working really fine but suddenly after the weekend it doesn't work anymore.

I get allways the following error after few seconds of running, so I get still a few data before the interrupt:

')' at line 1xception: Syntax error or access violation: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Angelo at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source) at com.mysql.jdbc.MysqlIO.sqlQuery(Unknown Source) at com.mysql.jdbc.Connection.execSQL(Unknown Source) at com.mysql.jdbc.Connection.execSQL(Unknown Source) at com.mysql.jdbc.Statement.executeQuery(Unknown Source) at com.mysql.jdbc.jdbc2.Statement.executeQuery(Unknown Source) at TestReader.main(TestReader.java:71) Exception in thread "main"

The problem seem to be in the syntax of the query. I don't understand why this happend, specially it worked before. I'm using MySQL-max-4.0.3beta and MySQL-connector-java-2.0.14. Tried to restart the server and updated to 4.0.4beta, but it's still not working.

The table: CREATE TABLE IF NOT EXISTS message ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, msg TEXT, time TIMESTAMP NOT NULL) TYPE=INNODB;

The program:

import java.io.*; import java.net.*; import java.lang.*; import java.util.*; import java.sql.*;

public class TestReader { public static void main(String argv[]) throws IOException, java.lang.ClassNotFoundException, java.sql.SQLException { String IpAddress = "165.118.43.239"; Socket sock=new Socket(IpAddress, 8000); BufferedReader dataIn = null;

//JDBC-Treiber laden Class.forName("com.mysql.jdbc.Driver");

//Datenbankverbindung aufbauen String URL = "jdbc:mysql://***/***"; String user = "***"; String pass = "***";

Connection con = DriverManager.getConnection(URL, user, pass);

//Statement erzeugen Statement stmt = con.createStatement();

try { dataIn = new BufferedReader(new InputStreamReader(sock.getInputStream()));

while(true){

String readsocket = dataIn.readLine()+"\r";

if (dataIn != null) { String[] result = readsocket.split("\r");

for (int i=0; i<result.length; i++) { String query = "INSERT INTO message (msg) VALUES('"+(result[i])+"')"; ResultSet rs = stmt.executeQuery(query); } } }

} catch (ConnectException sox) { try { System.out.println("Remote connection closed.");

sock.close(); }catch (IOException iox){} }catch (IOException iox) { System.err.println (iox); } } }

If anybody has some idea, i would really appreciate!!!