Solved

JBuilder2 and SQL

Posted on 2000-03-14
11
202 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

862 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

25 Experts available now in Live!

Get 1:1 Help Now