Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JBuilder2 and SQL

Posted on 2000-03-14
11
Medium Priority
?
243 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

618 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