jeudi 30 juin 2016

IF Statement using SQL data to set variable

I'm currently writing a java application which is used to print bar codes out, which the information for is obtained from a MySQL database. The data in SQL has a property which defines which type of bar code it is, value 1 = serialized and 2 = un-serialized. I was wondering how I would use an if statement to set a variable to define what type of bar-code is being used - in java.

On the SQL database the value for bar code type is 'FK_BarcodeTypeID'

The code I have so far is:

 String SQL ="SELECT  [PK_PrintQueueID]" +
            "      ,[FK_PrinterID]" +
            "      ,[FK_BarcodeTypeID]" +
            "      ,[Barcode]" +
            "      ,[Quantity]" +
            "      ,[QueueDate]" +
            "      ,[ProcessedDate]" +
            "  FROM [Brad].[dbo].[PrintQueue]" +
            " WHERE ProcessedDate IS NULL";

    //Declare variable connection.
    Connection connection = null;
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //get current date time with Date()
    Date date = new Date();
    // System.out.println(dateFormat.format(date));



    //
    try {
        connection = DriverManager.getConnection(connectionString);
        Statement stmt = connection.createStatement();
        Statement stmt2 = null;
        ResultSet rs = stmt.executeQuery(SQL);

        while (rs.next()) {
            System.out.println(rs.getString("Barcode"));
            // System.out.println(rs.getString("PK_PrintQueueID"));
            // System.out.println(rs.getString("ProcessedDate"));
            String SQL2 = "UPDATE PrintQueue SET ProcessedDate =   '"+dateFormat.format(date)+"' WHERE PK_PrintQueueID =     '"+rs.getString("PK_PrintQueueID")+"' ";
            // System.out.println(SQL2);

            String ZPL = "^XA ^FX BARCODE ^BY4,2,050   ^FO140,40^BC^FD"+rs.getString("Barcode")+"^FS ^XZ";
            System.out.println(ZPL);



            // THIS IF STATEMENT SETS TYPE OF BARCODE TO
            // TYPE 1 OR 2

            // if ("FK_BarcodeTypeID") = 1) {

I am struggling to work out how to do the above, therefore any advice is appriciated.

Thankyou!

Aucun commentaire:

Enregistrer un commentaire