Solved

JBuilder2 and SQL

Posted on 2000-03-14
11
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

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

Laminamia
0
 

Author Comment

by:Schlieper
ID: 2616912
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
ID: 2617069
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!

 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2617096
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
ID: 2617162
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
 

Accepted Solution

by:
WilliamCHall earned 100 total points
ID: 2617507
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
ID: 2619088
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
ID: 2619616
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
ID: 2619808
That`s right. Typical in my english descriptions: i usually forget the technical definitions... :(

Thank's...
0
 

Expert Comment

by:WilliamCHall
ID: 2624503
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
ID: 2624616
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

730 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