Need help with basic ready to program issue

if (rs != null)
{
System.out.println ("Query executed succesfully");
// rs.beforeFirst ();
System.out.println ("Cursor moved before first record");
rs.next ();
System.out.println ("Cursor pointing at first record");
String temp = rs.getString (1);
System.out.println ("Result of query is " + temp);
int count = Integer.parseInt (temp);

Results:

SELECT COUNT(*) AS Cnt FROM LOGIN WHERE Username = 'sadasd' AND Password = 'dsad';
Query executed
Query executed succesfully
Cursor moved before first record
Cursor pointing at first record
Mybtn1 has encountered a error:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

Seems like this damn exception won't leave me.
 
Try this

Code:
if (eve.getSource () == mybtn1)
        {

            String user = myuser.getText();
            String pass = mypass.getText();
            if ()!(user.equals("")||pass.equals("")))
            {
                lblnaam.setText ("Welcome to your profile, " + user + "                                          ");
                try
                {
                    String sql = "SELECT COUNT(*) AS Cnt FROM LOGIN WHERE Username = '" + user + "' AND Password = '" + pass + "';";
                    Ssytem.out.println(sql);
                    Resultset rst = stmt.executeQuery (sql);
                    System.out.println("Query executed");
                    if (rst!=null)
                    {
                        System.out.println("Query executed succesfully")
                        //rst.beforeFirst();
                        System.out.println("Cursor moved before first record");
                        rst.next();
                        System.out.println("Cursor pointing at first record");
                        String temp = rst.getString("Cnt");
                        rst.close();
                        System.out.println("Result of query is " + temp);
                        int count = Integer.parseInt(temp);
                        if (count == 1)
                        {
                            JOptionPane.showMessageDialog (null, "Redirecting you to profile management.. please wait a while.");
                            myframe.setVisible (false);
                            JOptionPane.showMessageDialog (null, "You are now entering your profile.");
                            JOptionPane.showMessageDialog (null, "Please be patient while stats are loading. . . . .");
                            myprofile.setVisible (true);
                        }
                        else
                        {
                            JOptionPane.showMessageDialog (null, "Incorrect. Please retry or contact a game manager.");
                        }
                    }
                }
                catch (Exception e)
                {
                    System.out.println ("Mybtn1 has encountered a error:");
                    e.printStackTrace ();
                }
            }
        }
 
Same story.
Successfully connected to the database.
SELECT COUNT(*) AS Cnt FROM LOGIN WHERE Username = 'dsadsa' AND Password = 'dsadsad';
Query executed
Query executed succesfully
Cursor moved before first record
Cursor pointing at first record
Mybtn1 has encountered a error:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
 
Can you upload your full Java file so I can read the whole thing. There's something weird going on here. What version of Access are you using?, and what is you base OS
 
A bit of Google has given me one last thing to try.

Change in your void DatabaseConnection ()

stmt = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

to just

stmt = con.createStatement();
 
Wow, that seems to have did the trick.

It works 100% now :)

Thanks alot!

Would you mind looking at this code quick:

The two IF"s at the top which are using my comboboxes are working as intended, however, I want to use a checkbox at the bottom where (if it is ticked...) everything is displayed. but I can't seem to get the code to work.

I think the two seperate parts are interfering, because when I comment out 1. (2. works fully - I tick the box and execute - everything prints out)

1.
Code:
public void actionPerformed (ActionEvent eve)
    {

        if (eve.getSource () == mybtn)
        {

            try
            {
                int cnt = 0;
                String sql = "Select * From Games";

                if (cmbo.getSelectedItem ().toString ().length () > 0)
                {
                    sql = sql + " WHERE Genre ='" + cmbo.getSelectedItem ().toString () + "'";
                    cnt = 1;
                }
                else
                {
                    cnt = 0;

                }

                if (cmbo2.getSelectedItem ().toString ().length () > 0)

                    {
                        if (cnt == 1)
                        {
                            sql = sql + " AND Rating = '" + cmbo2.getSelectedItem ().toString () + "'";

                        }
                        else
                        {
                            sql = sql + " WHERE Rating = '" + cmbo2.getSelectedItem ().toString () + "'";
                            cnt = 1;

                        }

                    }


                rs = stmt.executeQuery (sql);

2.
Code:
 if (check.isSelected ())
                {

                    while (rs.next ())
                    {

                        String Genre = rs.getString ("Genre");
                        String Popularity = rs.getString ("Popularity");
                        String HighestScore = rs.getString ("HighestScore");
                        String Rating = rs.getString ("Rating");
                        String PlayerName = rs.getString ("PlayerName");
                        String TournamentAvailable = rs.getString ("TournamentAvailable");
                        String Game = rs.getString ("Game");

                        data [cnt] [0] = Genre;
                        data [cnt] [1] = Popularity;
                        data [cnt] [2] = HighestScore;
                        data [cnt] [3] = Rating;
                        data [cnt] [4] = PlayerName;
                        data [cnt] [5] = TournamentAvailable;
                        data [cnt] [6] = Game;

                        cnt++;

                        table.updateUI ();

                    }


                }

            }


            catch (Exception e)
            {
                System.out.println ("Vraag 1 onsuksesvol");
                e.printStackTrace ();
            }
        }
 
Last edited:
Haha, I can't blame you for that ~ It has been tiring.

Thanks alot for the help.

Ongelukkig kan ek nie more nog werk daaraan :) More moet dit in wees.

Bye,
Shanse.
 
Last edited:
The two IF"s at the top which are using my comboboxes are working as intended, however, I want to use a checkbox at the bottom where (if it is ticked...) everything is displayed. but I can't seem to get the code to work.
What do you mean by everything?
 
In code 1 you're using 'cnt' as a means of true & false when you should being using boolean.
You should declare 'cnt' before the while loop in code 2.
 
and dont use variable names like "cnt", "stmt" "rs", etc

use "count", etc
 
Top
Sign up to the MyBroadband newsletter
X