• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

JBuilder2 and SQL

I'm a newcomer to the Java programming language and I am using Jbuilder2 Professional to make an applet to run in a website but am having some difficulty.
I'm making an applet that has a login page to get users to the tech support page.  What I'm having trouble with is the source code in Jbuilder2.  I need the user to proceed to frame 2 only if the login and password are correct, Here is the code I'm having a problem with:

void jdbToggleButton1_actionPerformed(ActionEvent e) {
      try {
        parameterRow1.setString("userID",dtbUserID.getText());
        parameterRow1.setString("pswd",dtbPswd.getText());
        queryDataSet1.executeQuery();


        if (queryDataSet1.getInteger[1] >0){
          Frame2 frame = new Frame2();
          frame.pack();
          frame.show();
        }

      }
      catch (DataSetException ex) {
      }

and this is what the SQL statement looks like:

select count(*) RecCount from Table1
where (Field1 = :Usr) and (Field2 = :ps)

our main problem is getting the value of RecCount, so if RecCount>0 then they can view the frame.
like I said, I'm a newcomer to Java so please be as thurough as possible.

-Schlieper
0
Schlieper
Asked:
Schlieper
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Laminamia063099Commented:
What problem are you having when you run the code?  What do you see happen?

Laminamia
0
 
SchlieperAuthor Commented:
This is the error I get.

Error: (152)variable getInteger not found in class borland.sql.dataset.QueryDataSet.

and I have the following imported at the beginning of the applet.

import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.applet.*;
import com.sun.java.swing.*;
import borland.jbcl.dataset.*;
import borland.sql.dataset.*;
import borland.sql.dataset.QueryDataSet;
import borland.dbswing.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import java.sql.*;


-Schlieper
0
 
Laminamia063099Commented:
Try the following:

Instead of:
 if (queryDataSet1.getInteger[1] >0){
                             Frame2 frame = new Frame2();
                             frame.pack();
                             frame.show();
                           }

Use:
 if (queryDataSet1.getInteger(1) >0){
                             Frame2 frame = new Frame2();
                             frame.pack();
                             frame.show();
                           }

getInteger should be a method, not an array variable.

Laminamia.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Laminamia063099Commented:
In Java, most times when you access data from a class, you do so through a method (function), because most instance data in each class is protected or private.  Most classes will have 'get's and 'set's, methods used to set class instance data and get class instance data.

When you see errors such as the one you got, many times it is a result of accessing member data and forgetting to do so in function call style, with parentheses.

Laminamia
0
 
SchlieperAuthor Commented:
ok, but now it just changed the error on me
the error is now

error (152)method getInteger(int) not found in class borland.sql.dataset.QueryDataSet.

0
 
WilliamCHallCommented:
Lookup the method to borland.sql.dataset.QueryDataSet.getInteger().  It might be QueryDataSet.getInt(String columName) or QueryDataSet.getInteger(String columnName).  You should just be able to pass the column name from your database as a string or the actual column number.  Just an aside note, columns in resultsets start at 1 not 0; at least with my experience in oracle.  Your code might look like:


if (queryDataSet1.getInteger("userID") >0){
                             Frame2 frame = new Frame2();
                             frame.pack();
                             frame.show();
                           }

You may also find that using straight JDBC will make your life easier instead of using Borland's stuff.  You could use a simple database connection class like the following to do all of your database transactions:

/**
 * Title:        MainDataSource<p>
 * Description:  To be used as a class to connect to an Oracle Database.<p>
 * Copyright:    Copyright (c) William C. Hall<p>
 * Company:      Actium<p>
 * @author William C. Hall
 * @version 1.0
 */
package database;

import java.sql.*;

public class MainDataSource
{
  private ResultSet pResults;

    public MainDataSource(String query) throws SQLException
    {

        //Set up the Oracle JDBC driver
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        //Connect to database
        Connection DB_conn = DriverManager.getConnection
          ("jdbc:oracle:thin:@YourDataBaseIP:1521:scott", "tiger", "orcl");
        //Create a JDBC statement object
        Statement statement_obj = DB_conn.createStatement();
        //Execute a query
        ResultSet results = statement_obj.executeQuery (query);

        setResults(results);
    }

    public void setResults(ResultSet results) {
      pResults = results;
    }

    public ResultSet getResults() {
      return pResults;
    }

 }
0
 
dmaguilloCommented:
In my experience, all that WilliamCHall said it`s ok. At last, using Borland's stuff you obtain more problems that solutions.

So, if you donĀ“t want change your code, you can try this: the first thing you must to do is check the "borland.sql.dataset.QueryDataSet" available methods. U can try with "getObject(int)" (this method exist in "java.sql.ResultSet"). It obtains data like and Object, and u can convert it (int, long, String,...).

Bye... :)
0
 
Laminamia063099Commented:
Note on dmaquillo's comment:  

You can't convert the Object returned by getObject(int index) to an int, long, etc, because these are primitive types.  You must cast it to the object it represents: Integer, String, etc.

I also agree that using the JDBC might be simpler, and the documentation more ample.

Laminamia :)

0
 
dmaguilloCommented:
That`s right. Typical in my english descriptions: i usually forget the technical definitions... :(

Thank's...
0
 
WilliamCHallCommented:
By the way, you may wish to take at the new, FREE, JBuilder Foundation Developer's Version from Borland.  It's written in Java and is way better and faster than JBuilder 2 and 3.  It has a much cleaner interface and it doesn't hog all your memory using the designer like JBuilder 3 does.
0
 
SchlieperAuthor Commented:
Thanks everyone for your input, I really appreciate it.  And thank you WilliamCHall, your solution worked and now I'm happy as a clam, have a nice day and I wish you all well.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now