Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ResultSet - MAX(Bestellnummer)

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

Ich habe ein Problem mit dem ResultSet!


    public static String generateID(LgSWBPS inpSWBPS)

    {

        StringBuffer tmpSQL;

        ResultSet tmpResultSet;

        Statement tmpStatement;


        // Initialisierung

        tmpSQL = new StringBuffer();

        tmpResultSet = null;

        tmpStatement = null;


        setInitializedProperties();


        try {

            tmpSQL.append("SELECT MAX(Bestellposition) AS Bestellposition FROM Bestellungen";

            tmpSQL.append(" WHERE FIR = '"+inpSWBPS.getFIR()+"'");

            tmpSQL.append(" AND BSNR = '"+inpSWBPS.getBSNR()+"'");

        }   catch(Exception exc)    {

            System.out.println("Fehler in TableSWBPS.generateID(): tmpSQL.append(...)");

            exc.printStackTrace();

        }


        try {

            tmpStatement =

                DBConnection.getDBConnection().createStatement(

                    ResultSet.TYPE_SCROLL_INSENSITIVE,

                    ResultSet.CONCUR_READ_ONLY);


            tmpResultSet = tmpStatement.executeQuery(tmpSQL.toString());


        }   catch(SQLException exc) {

            System.out.println("Fehler in TableSWBPS.generateID(): SQLException!");

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

            exc.printStackTrace();

        }   catch(Throwable thr)    {

            System.out.println("Fehler in TableSWBPS.generateID(): Throwable!");

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

            thr.printStackTrace();

        }

        String strID;

        try {

            int id = Integer.parseInt(tmpResultSet.getString("Bestellposition").trim())+1;

            DecimalFormat df = new DecimalFormat("00000");

            strID = df.format(id);

        }   catch(Exception e)  {

            System.out.println("Fehler");

            strID = "00001";

        }


        return strID;

    } 
So ist mein Code momentan! Mein Ziel mit dieser Methode soll es sein die nächste Bestellposition zu einer Bestellnummer zu bekommen. Bis jetzt bekomme ich aber immer eins zurück. Ich denke, dass es an der Zeile liegt
tmpResultSet.getString("Bestellposition")

Was mache ich falsch?

Moin,

ich glaube du must zuerst die next() Methode des ResultSets aufrufen, bevor Du auf dieses zugreifen kannst.

Klappt es dann?

Grüße, Peter

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.