Witajcie,
Proszę o pomoc. Próbuję wykonać dwa zapytania (tylko dla testu są one takie same). W rezultacie pierwsze zapytanie jest realizowane, w drugim pojawia się SQLException (java.sql.SQLException: ResultSet is from UPDATE. No Data.).
Gdzie tkwi mój błąd ?

Oczywiście dodaje kod, z którego usunałęm zbędne rzeczy:

  1. Główna klasa, w metodzie klasy uruchamiane jest zapytanie SQL.
package barcodeReader;

import dbConnection.SQLQueryCheckUser;

public class Reader {

	public static void main(String[] args) throws Exception {
		// zmienna pomocnicza
		String us_workerID = "777777";
		// zapytnie
		String queryCheckUser = "SELECT us_name, us_surname, us_position, us_lockMachine, us_machine FROM sls_user WHERE us_workerID="
				+ us_workerID;

		String[] resultOfSQLQueryCheckUser = null;

		System.out.println(queryCheckUser);
		try {
			// wywołanie zapytania
			resultOfSQLQueryCheckUser = SQLQueryCheckUser.query(queryCheckUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
		// wywołanie metody wyskakującego onka (powycinałem nieistotną część
		// kodu)
		TimeLineOperatorMenu.popUp("Czas operatora", "20", us_workerID);
	}
} 

SQLQueryCheckUser:

package dbConnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SQLQueryCheckUser {

	public static String[] query(String query) throws Exception {

		Connection connectionSLS = ConnectionSLSdb.makeConnection();
		Statement statementSLS = null;

		try {
			statementSLS = connectionSLS.createStatement();
		} catch (Exception exc) {
			System.out.println(exc);
			System.exit(1);
		}

		ResultSet resultOfQuery = null;
		try {
			resultOfQuery = statementSLS.executeQuery(query);

		} catch (SQLException exc) {
			System.out.println("SQL except.: " + exc.getMessage());
			System.out.println("SQL state  : " + exc.getSQLState());
			System.out.println("Vendor errc: " + exc.getErrorCode());

			System.exit(1);
		}

		String[] result = new String[5];

		if (!resultOfQuery.next()) {
			System.out.println("null");// U S U Ń ! ! !********
			result[0] = "noAnswer";
		} else {
			resultOfQuery.beforeFirst();
			while (resultOfQuery.next()) {
				result[0] = resultOfQuery.getString(1);
				result[1] = resultOfQuery.getString(2);
				result[2] = resultOfQuery.getString(3);
				result[3] = resultOfQuery.getString(4);
				result[4] = resultOfQuery.getString(5);
				System.out.println("result:  " + result[0] + " " + result[1]
						+ " " + result[2] + " " + result[3] + " " + result[4]);
			}
		}

		try {
			statementSLS.close();
			connectionSLS.close();
		}

		catch (SQLException exc) {
			System.out.println(exc);
			System.exit(1);
		}
		return result;
	}
}
 

TimeLineOperatorMenu:

package barcodeReader;
import dbConnection.SQLQueryActivities;
import dbConnection.SQLQueryCheckUser;

public class TimeLineOperatorMenu {
	public static void popUp(String headerOfFrame, String line,
			String us_workerID) {

		String queryActivities = "SELECT us_name, us_surname, us_position, us_lockMachine, us_machine FROM sls_user WHERE us_workerID="
				+ us_workerID;
		String[] resultOfSQLQueryActivities = null;

		System.out.println(queryActivities);
		try {
			resultOfSQLQueryActivities = SQLQueryActivities
					.query(queryActivities);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 

SQLQueryActivities:

package dbConnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SQLQueryActivities {

	public static String[] query(String query) throws Exception {

		Connection connectionSLS = ConnectionSLSdb.makeConnection();
		Statement statementSLS = null;

		try {
			statementSLS = connectionSLS.createStatement();
		} catch (Exception exc) {
			System.out.println(exc);
			System.exit(1);
		}

		ResultSet resultOfQuery = null;
		try {
			statementSLS.executeQuery(query);
			resultOfQuery = statementSLS.getResultSet();

		} catch (SQLException exc) {
			System.out.println("SQL except.: " + exc.getMessage());
			System.out.println("SQL state  : " + exc.getSQLState());
			System.out.println("Vendor errc: " + exc.getErrorCode());
			System.exit(1);

		}

		String[] result = new String[5];

		if (!resultOfQuery.next()) {
			System.out.println("null");// U S U Ń ! ! !********
			result[0] = "noAnswer";
		} else {
			resultOfQuery.beforeFirst();
			while (resultOfQuery.next()) {
				result[0] = resultOfQuery.getString(1);
				result[1] = resultOfQuery.getString(2);
				result[2] = resultOfQuery.getString(3);
				result[3] = resultOfQuery.getString(4);
				result[4] = resultOfQuery.getString(5);
				System.out.println("result:  " + result[0] + " " + result[1]
						+ " " + result[2] + " " + result[3] + " " + result[4]);
			}
		}

		try {
			statementSLS.close();
			connectionSLS.close();
		}

		catch (SQLException exc) {
			System.out.println(exc);
			System.exit(1);
		}

		return result;
	}
}


dbConnection

package dbConnection;
import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectionSLSdb {

	public static Connection makeConnection() {
		Connection connectionSLS = null;
		String databaseSLS = "jdbc:mysql://localhost:3306/sls";
		String userSLS = "root";
		String passSLS = "test";

		try {
			Class.forName("com.mysql.jdbc.Driver");

			connectionSLS = DriverManager.getConnection(databaseSLS, userSLS,
					passSLS);
		} catch (Exception exc) {
			System.out.println(exc);
			System.exit(1);
		}
		
		return connectionSLS;
	}
}

 

Z góry dziękuję za pomoc ! :-)