Debug Incompresibile - Esecuzione Query Jdbc

di il
3 risposte

Debug Incompresibile - Esecuzione Query Jdbc

Salve,

Questo è il mio codice:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Panthera {

	private static final String DB_DRIVER = "COM.ibm.db2.jdbc.net.DB2Driver";
	private static final String DB_CONNECTION = "jdbc:db2://10.12.230.83:50001/PANTH01";
	private static final String DB_USER = "finance";
	private static final String DB_PASSWORD = "finance";

	public static void main(String[] args) throws Exception {

		Scanner in = new Scanner(System.in);
		Panthera panthera = new Panthera();
			
		try {

			// Display menu
			System.out.println("**SELECT TABLE**");
			System.out.println("1\t THERA.CLASS_HDR --> (FW_DATA_OWNER_ID)");
			System.out.println("2\t THERA.CLASS_HDR_NLS --> (CLASS_NAME) AND (LANGUAGE)");
			System.out.println("3\t THERA.CLASSAD_NLS --> (CLASS_NAME) AND (LANGUAGE)");
			System.out.println("4\t THERA.ENUM_NLS --> (ATTRIBUTE_REF) AND (LANGUAGE)");

			System.out.println("Fai una scelta:");
			int selezionaMenu = in.nextInt();

			switch (selezionaMenu) {
			case 1:
				System.out.println("THERA.CLASS_HDR --> (FW_DATA_OWNER_ID)");
				System.out.println("Inserisci FW_DATA_OWNER_ID: ");
				String fwOwnerId = in.next();
				panthera.setRecordTableHDR(fwOwnerId);
				break;
			case 2:
				System.out.println("THERA.CLASS_HDR_NLS --> (CLASS_NAME) AND (LANGUAGE)");
				System.out.println("Inserisci CLASS_NAME: ");
				String clNameHdrNls = in.next();
				System.out.println("Inserisci LANGUAGE: ");
				String langHdrNls = in.next();
				panthera.setRecordTableHDR_NLS(clNameHdrNls,langHdrNls);
				break;
			case 3:
				System.out.println("THERA.CLASSAD_NLS --> (CLASS_NAME) AND (LANGUAGE)");
				System.out.println("Inserisci CLASS_NAME: ");
				String clNameClassadNls = in.next();
				System.out.println("Inserisci LANGUAGE: ");
				String langClassadNls = in.next();
				panthera.setRecordTableClassadNls(clNameClassadNls,langClassadNls);
				break;
			case 4:
				System.out.println("THERA.ENUM_NLS --> (ATTRIBUTE_REF) AND (LANGUAGE)");
				System.out.println("Inserisci ATTRIBUTE_REF: ");
				String attRef = in.next();
				System.out.println("Inserisci LANGUAGE: ");
				String langEnumNls = in.next();
				panthera.setRecordTableEnumNls(attRef,langEnumNls);
				break;
			default:
				System.out.println("Non Trovato");
			}

		} catch (SQLException e) {

			System.out.println(e.getMessage());

		}

	}

	
	private void setRecordTableEnumNls(String attributeRef, String language) throws Exception {

		Connection dbConnection = null;
		PreparedStatement preparedStatement = null;

		String selectSQL = "select * from THERA.ENUM_NLS  where ATTRIBUTE_REF = ? AND LANGUAGE = ?";

		try {
			dbConnection = getConnection();
			preparedStatement = dbConnection.prepareStatement(selectSQL);
			preparedStatement.setString(1, attributeRef);
			preparedStatement.setString(2, language);

			ResultSet rs = preparedStatement.executeQuery();

			while (rs.next()) {

				System.out.println("**Table: THERA.ENUM_NLS**");
				attributeRef = rs.getString("ATTRIBUTE_REF");
				int enumValue = rs.getInt("ENUM_VALUE");
				language = rs.getString("LANGUAGE");
				String enumDesc = rs.getString("ENUM_DESC");
				
				System.out.println("attributeRef : " + attributeRef);
				System.out.println("enumValue : " + enumValue);
				System.out.println("language : " + language);
				System.out.println("enumDesc : " + enumDesc);
			}

		} catch (SQLException e) {

			System.out.println(e.getMessage());

		} finally {

			if (preparedStatement != null) {
				preparedStatement.close();
			}

			if (dbConnection != null) {
				dbConnection.close();
			}

		}

	}
	
	private void setRecordTableClassadNls(String classname, String language) throws Exception {

		Connection dbConnection = null;
		PreparedStatement preparedStatement = null;

		String selectSQL = "select * from THERA.CLASSAD_NLS  where CLASS_NAME = ? and LANGUAGE= ?";

		try {
			dbConnection = getConnection();
			preparedStatement = dbConnection.prepareStatement(selectSQL);
			preparedStatement.setString(1, classname);
			preparedStatement.setString(2, language);

			ResultSet rs = preparedStatement.executeQuery();

			while (rs.next()) {

				System.out.println("**Table: THERA.CLASSAD_NLS**");
				classname = rs.getString("CLASS_NAME");
				String attributeName = rs.getString("ATTRIBUTE_NAME");
				language = rs.getString("LANGUAGE");
				String nlsAttributeName = rs.getString("NLS_ATTRIBUTE_NAME");
				String nlsColumnTitle = rs.getString("NLS_COLUMN_TITLE");
				String nlsLabel = rs.getString("NLS_LABEL");
				
				System.out.println("classname : " + classname);
				System.out.println("attributeName : " + attributeName);
				System.out.println("language : " + language);
				System.out.println("nlsAttributeName : " + nlsAttributeName);
				System.out.println("nlsColumnTitle : " + nlsColumnTitle);
				System.out.println("nlsLabel : " + nlsLabel);

			}

		} catch (SQLException e) {

			System.out.println(e.getMessage());

		} finally {

			if (preparedStatement != null) {
				preparedStatement.close();
			}

			if (dbConnection != null) {
				dbConnection.close();
			}

		}

	}
	
	
	private void setRecordTableHDR_NLS(String classname, String language) throws Exception {

		Connection dbConnection = null;
		PreparedStatement preparedStatement = null;

		String selectSQL = "select * from THERA.CLASS_HDR_NLS  where CLASS_NAME = ? AND LANGUAGE= ?";

		try {
			dbConnection = getConnection();
			preparedStatement = dbConnection.prepareStatement(selectSQL);
			preparedStatement.setString(1, classname);
			preparedStatement.setString(2, language);

			ResultSet rs = preparedStatement.executeQuery();

			while (rs.next()) {

				System.out.println("**Table: THERA.CLASS_HDR_NLS**");
				classname = rs.getString("CLASS_NAME");
				language = rs.getString("LANGUAGE");
				String nlsClassName = rs.getString("NLS_CLASS_NAME");
				String nlsPlClassName = rs.getString("NLS_PL_CLASS_NAME");
				
				System.out.println("className : " + classname);
				System.out.println("language : " + language);
				System.out.println("nlsClassName : " + nlsClassName);
				System.out.println("nlsPlClassName : " + nlsPlClassName);

			}

		} catch (SQLException e) {

			System.out.println(e.getMessage());

		} finally {

			if (preparedStatement != null) {
				preparedStatement.close();
			}

			if (dbConnection != null) {
				dbConnection.close();
			}

		}

	}
	
	
	
	private void setRecordTableHDR(String fwDataOwnerId) throws Exception {

		Connection dbConnection = null;
		PreparedStatement preparedStatement = null;

		String selectSQL = "select * from THERA.CLASS_HDR where FW_DATA_OWNER_ID = ?";

		try {
			dbConnection = getConnection();
			preparedStatement = dbConnection.prepareStatement(selectSQL);
			preparedStatement.setString(1, fwDataOwnerId);

			ResultSet rs = preparedStatement.executeQuery();

			while (rs.next()) {

				String className = rs.getString("CLASS_NAME");
				String description = rs.getString("DESCRIPTION");
				String fetchSize = rs.getString("FETCH_SIZE");
				String doListClass = rs.getString("DO_LIST_CLASS");
				String actionAdapter = rs.getString("ACTION_ADAPTER");
				String objectFrame = rs.getString("OBJECT_FRAME");
				String constrainde = rs.getString("CONSTRAINED");
				String boClassName = rs.getString("BO_CLASS_NAME");
				String iconName = rs.getString("ICON_NAME");
				String secondary = rs.getString("SECONDARY");
				String compPresent = rs.getString("COMP_PRESENT");
				String relPresent = rs.getString("REL_PRESENT");
				fwDataOwnerId = rs.getString("FW_DATA_OWNER_ID");
				String fatherClassName = rs.getString("FATHER_CLASS_NAME");
				String objectFormWeb = rs.getString("OBJECT_FORM_WEB");
				String doListClassWeb = rs.getString("DO_LIST_CLASS_WEB");
				String actionAdapterWeb = rs.getString("ACTION_ADAPTER_WEB");
				String helpObjectFrame = rs.getString("HELP_OBJECT_FRAME");
				String helpQuality = rs.getString("HELP_QUALITY");
				String helpFormWeb = rs.getString("HELP_FORM_WEB");

				System.out.println("**Table: THERA.CLASS_HDR**");
				System.out.println("className : " + className);
				System.out.println("description : " + description);
				System.out.println("fetchSize : " + fetchSize);
				System.out.println("doListClass : " + doListClass);
				System.out.println("actionAdapter : " + actionAdapter);
				System.out.println("objectFrame : " + objectFrame);
				System.out.println("constrainde : " + constrainde);
				System.out.println("boClassName : " + boClassName);
				System.out.println("iconName : " + iconName);
				System.out.println("secondary : " + secondary);
				System.out.println("compPresent : " + compPresent);
				System.out.println("relPresent : " + relPresent);
				System.out.println("fwDataOwnerId : " + fwDataOwnerId);
				System.out.println("fatherClassName : " + fatherClassName);
				System.out.println("objectFormWeb : " + objectFormWeb);
				System.out.println("doListClassWeb : " + doListClassWeb);
				System.out.println("actionAdapterWeb : " + actionAdapterWeb);
				System.out.println("helpObjectFrame : " + helpObjectFrame);
				System.out.println("helpQuality : " + helpQuality);
				System.out.println("helpFormWeb : " + helpFormWeb);

			}

		} catch (SQLException e) {

			System.out.println(e.getMessage());

		} finally {

			if (preparedStatement != null) {
				preparedStatement.close();
			}

			if (dbConnection != null) {
				dbConnection.close();
			}

		}

	}


	
	private static Connection getConnection() throws Exception {
	  	
		try {
	    		Class.forName(DB_DRIVER);
	    		return DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
	  	   }
	 	catch (  SQLException sqlex) {
	    		sqlex.printStackTrace();
	  		}
		catch (  Exception ex) {
	    		ex.printStackTrace();
	  	}
	  	return null;
		}

}

Quando seleziono 1:
1 Output:
**SELECT TABLE**
1 THERA.CLASS_HDR --> (FW_DATA_OWNER_ID)
2 THERA.CLASS_HDR_NLS --> (CLASS_NAME) AND (LANGUAGE)
3 THERA.CLASSAD_NLS --> (CLASS_NAME) AND (LANGUAGE)
4 THERA.ENUM_NLS --> (ATTRIBUTE_REF) AND (LANGUAGE)
Fai una scelta:
1
THERA.CLASS_HDR --> (FW_DATA_OWNER_ID)
Inserisci FW_DATA_OWNER_ID:
PRIMROSE

Dopo 2 minuti o più:
Errore:
COM.ibm.db2.jdbc.DB2Exception: [IBM][Programma di controllo JDBC] CLI0615E Errore nella ricezione dal socket, il server non risponde. SQLSTATE=08S01
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.throwReceiveError(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Request.receive(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Request.sendAndRecv(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.SQLConnect(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.SQLConnect(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.create(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.<init>(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at it.panthera.Panthera.getConnection(Panthera.java:313)
at it.panthera.Panthera.setRecordTableHDR(Panthera.java:236)
at it.panthera.Panthera.main(Panthera.java:39)
Exception in thread "main" java.lang.NullPointerException
at it.panthera.Panthera.setRecordTableHDR(Panthera.java:237)
at it.panthera.Panthera.main(Panthera.java:39)

2 Output:

**SELECT TABLE**
1 THERA.CLASS_HDR --> (FW_DATA_OWNER_ID)
2 THERA.CLASS_HDR_NLS --> (CLASS_NAME) AND (LANGUAGE)
3 THERA.CLASSAD_NLS --> (CLASS_NAME) AND (LANGUAGE)
4 THERA.ENUM_NLS --> (ATTRIBUTE_REF) AND (LANGUAGE)
Fai una scelta:
1
THERA.CLASS_HDR --> (FW_DATA_OWNER_ID)
Inserisci FW_DATA_OWNER_ID:
Connesso --> DB_DRIVER
PRIMROSE
NON Connesso --> DriverManager
COM.ibm.db2.jdbc.DB2Exception: [IBM][Programma di controllo JDBC] CLI0615E Errore nella ricezione dal socket, il server non risponde. SQLSTATE=08S01
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.throwReceiveError(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Request.receive(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Request.sendAndRecv(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.SQLConnect(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.SQLConnect(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.create(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Connection.<init>(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at it.panthera.Panthera.getConnection(Panthera.java:314)
at it.panthera.Panthera.setRecordTableHDR(Panthera.java:236)
at it.panthera.Panthera.main(Panthera.java:39)
Exception in thread "main" java.lang.NullPointerException
at it.panthera.Panthera.setRecordTableHDR(Panthera.java:237)
at it.panthera.Panthera.main(Panthera.java:39)

Come mai?
Dove ho sbagliato?

3 Risposte

Devi accedere o registrarti per scrivere nel forum
3 risposte