This discussion is archived
12 Replies Latest reply: Jan 6, 2013 7:59 PM by 983060 RSS

Beginner Error, Urgent help please!

983060 Newbie
Currently Being Moderated
Hello, I am a beginner at programming and I am currently going through the Database 11g XE Two day plus Java, so I am using Jdeveloper. All has been going well, until I came upon the filter by name portion. I have followed the instructions to a tee, and after several checks everything matches with the tutorial. However, I am receiving an error. I am using a JSP page, and two classes: DataHandler.java , and JavaClient. java. The getEmployeesByName class is located inside DataHandler.java ; as well as the getAllEmployees class that I used earlier in the tutorial. However, when I add in the getEmployeesByName class on the JSP after a form, I recieve an error saying that method getEmployeesByName could not be found. It has been an hour and I can't find my mistake.

Here is  my code:

For JavaClient.java:
 package hr;

import java.sql.ResultSet;

public class JavaClient {
    public JavaClient() {                           
        super();
    }

    public static void main(String[] args) throws Exception {
        DataHandler datahandler = new DataHandler();
        ResultSet rset = datahandler.getAllEmployees();
        
        while (rset.next()) {
        System.out.println(rset.getInt(1) + " " +
            rset.getString(2) + " " +
            rset.getString(3) + " " +
            rset.getString(4));  
            
            rset = datahandler.getEmployeesByName("King");
             
            System.out.println("\nResults from query: ");
             
            while (rset.next()) {
              System.out.println(rset.getInt(1) + " " + 
              rset.getString(2) + " " + 
              rset.getString(3) + " " + 
              rset.getString(4));
            }   
        }
        
    }
}
For DataHandler.java
package hr;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import oracle.jdbc.pool.OracleDataSource;


public class DataHandler {
    public DataHandler() {
    }
    String jdbcUrl = null;
    String userid = null;
    String password = null;
    Connection conn;
    Statement stmt;
    ResultSet rset;
    String query;
    String sqlString;

    public void getDBConnection() throws SQLException{
        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL(jdbcUrl);
        conn = ds.getConnection(userid,password);
    }
    public ResultSet getAllEmployees() throws SQLException{
        getDBConnection();
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        query = " SELECT * FROM Employees ORDER BY employee_id";
        System.out.println("\nExecuting query: " + query);
        rset = stmt.executeQuery(query);
        return rset;
    }
    public ResultSet getEmployeesByName(String name) throws SQLException{
        name = name.toUpperCase();
        getDBConnection();
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, 
                                    ResultSet.CONCUR_READ_ONLY);
        query =
        "SELECT * FROM Employees WHERE UPPER(first_name) LIKE \'%" + name + "%\'" +
        " OR UPPER(last_name) LIKE \'%" + name + "%\' ORDER BY employee_id";
        System.out.println("\nExecuting query: " + query);
        rset = stmt.executeQuery(query);
        return rset; 
    }
}
for the JSP page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252" import="java.sql.ResultSet"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
        <title>employees</title>
        <link type="text/css" rel="stylesheet" href="resources/css/jdeveloper.css"/>
    </head>
    <body>
        <h2 align="center">
            AnyCo Corporation
        </h2><h3>
            Employee Data 
           
             
        </h3> <jsp:useBean id="empsbean" class="hr.DataHandler" scope="session"/>
        <form action="employees.jsp">
            Filter by Name:
            <input type="text" name="query"/>
            <input type="submit" value="Filter"/>
        </form>
        <%ResultSet rset;
String query = request.getParameter("query");
if (query != null && query != null)
  rset = empsbean.getEmployeesByName(query);
else
  rset = empsbean.getAllEmployees();%>
        <table cellspacing="2" cellpadding="3" border="1" width="100%">
            <tr>
                <td width="17%">
                    <h4>
                        First Name
                    </h4>
                </td>
                <td width="17%">
                    <h4>
                        Last Name
                    </h4>
                </td>
                <td width="17%">
                    <h4>
                        Email
                    </h4>
                </td>
                <td width="17%">
                    <h4>
                        Job
                    </h4>
                </td>
                <td width="16%">
                    <h4>
                        Phone
                    </h4>
                </td>
                <td width="16%">
                    <h4>
                        Salary
                    </h4>
                </td>
            </tr><%while (rset.next ())
    {
    out.println("<tr>");
    out.println("<td>" + 
      rset.getString("first_name") + "</td><td> " + 
      rset.getString("last_name") + "</td><td> " + 
      rset.getString("email") + "</td><td> " + 
      rset.getString("job_id") + "</td><td>" + 
      rset.getString("phone_number") + "</td><td>" + 
      rset.getDouble("salary") + "</td>");
    out.println("</tr>");
    }%>
        </table>
    </body>
</html>
I know this is a very big question, but I am lost and the tutorial isn't offering any further guidance. I have a deadline to meet soon, so thanks in advance for help.

The version of Jdev is Studio Edition 11.1.2.3.0

I am not aware of those other two interface options. Are there any tutorials that could help get me started on using those instead of JSP?

Edited by: DanDan Sc on Jan 5, 2013 9:41 AM

Edited by: DanDan Sc on Jan 5, 2013 9:44 AM
  • 1. Re: Beginner Error, Urgent help please!
    Timo Hahn Oracle ACE
    Currently Being Moderated
    User, welcome to the forum.

    Please read the FAQ (https://forums.oracle.com/forums/help.jspa) and format the code you post in this forum. Right now it's too hard to read.

    Next you should always tell us the exact JDev version you are using. 11g in not enough as there are a couple of 11g versions out in the wild.

    May I ask you another question: why do you user plain jsp as ui technology? This is quite old. Nowadays JSF and ADF are popular.


    Timo
  • 2. Re: Beginner Error, Urgent help please!
    983060 Newbie
    Currently Being Moderated
    I edited it, I apologize for that.

    Also, I am doing this for a competitive project due in under two weeks.I must be able to show all the source code. So do JSF or ADF allow you to view all source? Also which one would be easier to create an app that queries data from a database, edit data in the database, and provide log in functionality? The app must work offline as well.

    Edited by: DanDan Sc on Jan 5, 2013 10:56 AM
  • 3. Re: Beginner Error, Urgent help please!
    dvohra21 Oracle ACE
    Currently Being Moderated
    Use a JSF with a managed bean associated for bean properties. With JSF, the bean properties may be used in a JSF page with EL Expression.
    http://docs.oracle.com/cd/E13224_01/wlw/docs103/guide/webapplications/jsf/jsf-integration-tutorial/tutJSFIntro.html
  • 4. Re: Beginner Error, Urgent help please!
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Thanks for formatting the code. Much easier to read.

    What I don't get are your requirements. Do you try to create a web application?
    Stand alone application?
    If yes, what do you mean by 'the app must be run offline too'?
    Without a db? Without a web server?

    Timo
  • 5. Re: Beginner Error, Urgent help please!
    983060 Newbie
    Currently Being Moderated
    Well the problem with this code is that i recieve am error on the JSP page saying error method getEmployeesByName could not be found. But my requirements are: the application must be put on a USB drive with an executable file to run the app. It must include database files saved as .txt files, which will be queried and edited through the application. I am overwhelmed with all the options, and my deadline is rapidly approaching. What would you recommend to do this? Thank you in advance for the help.
  • 6. Re: Beginner Error, Urgent help please!
    983060 Newbie
    Currently Being Moderated
    Does anyone have suggestions on how to do such a thing?
  • 7. Re: Beginner Error, Urgent help please!
    bigchill Newbie
    Currently Being Moderated
    Hi Dan

    firstly, looking at your example app, seems like you are not using ADF but only a oracle db. apart from that, its pure java/jdbc and a dao
    secondly, your requirements are not clear or overloaded.

    I'm going to assume (a) you know what your requirements are and (b) you have selected the technolgies based on your intial research. So I'm not going to veer from all that or suggest you something else.

    if you answered YES to (a) and (b) then fine, else let me know otherwise as its crucial.

    Going with what you have, please answer the following:
    1) explain how you deploy this app
    2) post the full error message
  • 8. Re: Beginner Error, Urgent help please!
    983060 Newbie
    Currently Being Moderated
    After doing much more research, I have decided to start over and use an Offline Database inside Jdeveloper, and I will likely use ADF or JSF to develop it now. I'm figuring it out as I go. The thing I'm now stuck on is how do I get the data files in my database to save as .txt files? Jdev says that they are saved as .xml files, so do I have a choice here? That is my only specific question now. I'm basically just jumping in and looking at examples to learn how to do the things i need.
  • 9. Re: Beginner Error, Urgent help please!
    bigchill Newbie
    Currently Being Moderated
    when you say offline database do u mean a stub java class with helper methods that returns data back based on hardcoded fields in the class? If YES, then fine. by doing this you leave out the jdbc connection/driver and other sql code in your dao and make it more simpler. If NO, then what do u mean by offline db.
  • 10. Re: Beginner Error, Urgent help please!
    983060 Newbie
    Currently Being Moderated
    Well I created a new project and right clicked and selected new>database tier> offline database objects> offline database; In Jdeveloper. Then I created tables with the columns I needed. I'm going to be honest, I have no experience with this. In general this is what I need to do: develop a program that is executable off of a CD or USB drive that begins with a login page, then a home page. Then the user must be able to navigate to pages where they can add employees, or employers contracted; and edit their data (address phone, etc.) Then they must be able to go to a page that is unique for each employee to perform an evaluation. They will input numerical scores and comments, and save the evaluation. Then they must be able to go to the employee's page and pull reports of saved evaluations. Other reports must be possible such as: all employees, all employers, and a more detailed report for each individual. So if you were tasked with this, how would you do it? I find myself buried with all the different methods Jdeveloper provides.
  • 11. Re: Beginner Error, Urgent help please!
    bigchill Newbie
    Currently Being Moderated
    DanDan

    your answer can be divided into 2 very broad categories.
    1) non-functional requirement and
    2) functional requirements

    point 1 is how the system is deployed or usable, and point 2 is how the system should behave from a user perspective, which could be divided into 1 ore more usecases. your app seems to have more than half a dozen usecases - much likely more by looking at it form a high level...

    If I was tasked with this,
    CASE1:(Assumtion here is Knowledge=BEGINNER)
    and only 2 weeks were given from completion, then I'd work with the technoliges I already know and try not doing it with a new techonlogy given ADF high sophistication, customisation capabilities and complexity. Having said this, it can be still possible but you will require a lot and I still dont think 2 weeks will do it.

    CASE2:(assumption here is Knowledge=INTER-ADV)
    and only 2 weeks were given from completion, then this would be a standalone app deployed on a memory device that is runnable by launching the application.
    Currently my work is using ADF, Web and JEE technolgies. The standalone application development have evolved rapidly since I last did my bit in that space. Having said that, I'd create the same application without a JSP, I'd use SWING as a frontend, have a database since you have a lot of data manipulation like CRUD etc., and then deploy the application as an executable jar file which when double clicked launches itself. The time I last did something like this, it was with Java Webstart, and now it mught have eveloved into something better.
    Again here, if you are going to LEARN Swing then you'll fall into the CASE1 bracket which will alter your Estimated completion time.

    And at the end of the day; how I'd go about this problem/reaserach would be different based on the individual and what resources one has at their disposal.
  • 12. Re: Beginner Error, Urgent help please!
    983060 Newbie
    Currently Being Moderated
    Alright, I'll see what I can do. Thank you for the help.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points