Solved

JBuilder2 and SQL

Posted on 2000-03-14
11
191 Views
Last Modified: 2008-02-01
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
Comment
Question by:Schlieper
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:Laminamia063099
Comment Utility
What problem are you having when you run the code?  What do you see happen?

Laminamia
0
 

Author Comment

by:Schlieper
Comment Utility
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
 
LVL 3

Expert Comment

by:Laminamia063099
Comment Utility
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
 
LVL 3

Expert Comment

by:Laminamia063099
Comment Utility
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
 

Author Comment

by:Schlieper
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Accepted Solution

by:
WilliamCHall earned 100 total points
Comment Utility
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
 
LVL 1

Expert Comment

by:dmaguillo
Comment Utility
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
 
LVL 3

Expert Comment

by:Laminamia063099
Comment Utility
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
 
LVL 1

Expert Comment

by:dmaguillo
Comment Utility
That`s right. Typical in my english descriptions: i usually forget the technical definitions... :(

Thank's...
0
 

Expert Comment

by:WilliamCHall
Comment Utility
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
 

Author Comment

by:Schlieper
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now