Java.beans.Statement

I have a program which is reporting the rather useless error:
java.lang.NullPointerException
Continuing ...I finally traced it down to the java.beans.Statement class, which has the following bit of useless code:
static ExceptionListener defaultExceptionListener = new ExceptionListener() {
        public void exceptionThrown(Exception e) {
            System.err.println(e);
            // e.printStackTrace();
            System.err.println("Continuing ...");
    };You will note the commented out stack trace ! I have no way of knowing where the exception occured and every time it occurs an element of a CORBA conection I have (using third party libraries) falls over.
Any Ideas how I can get it to report something useful ? Note that I cannot debug it as the error occurs on a live environment which handles thousands of interactions an hour.

I don't think you understand the problem. The code quoted is JRE code, notice the class name "java.beans.Statement". I searched the entire JRE source to find something that could be generating the "phantom" exception, as niether my code, nor the third party CORBA code (according to the supplier), output that message.
java.beans.Statement is the only class in the entier JRE that outputs that message in that format, hence it has to be the class reporting the error. Unfortunately, someone in thier wisdom commented out the stack trace code before compiling the JRE, so I have no way of telling what casused the error.
So I need to know if there is a way of rerouting or overriding or something, just so I can see the stack trace.

Similar Messages

  • Java.beans.Statement & java.sql.Statement

    My old code from jdk1.3.1 throws the ambiguous class thingie-mo-bob. Why did they implement the new java.beans.Statement, and is there anyway to make it default to the old java.sql.Statement without having to go through all the old code and add import java.sql.Statement. I have like 200 jsp files 'n it will take a loooong time!
    Pete

    There r two ways to do this.
    (i) One is Implement the java.sql.Statement
    like
    package java.beans;
    public interface Statement implements
    java.sql.Statement {
    }What? Are you suggesting he edit the source code for java.beans.Statement and make it implement java.sql.Statement?? I would most certainly not suggest that solution- beside violating the licensing agreement, it has troubling consequences since you are basically redefining the structure of a class in a way that makes no functional sense- that is, there is no reason for java.beans.Statement to implement methods like getConnection() and the other signatures of java.sql.Statement.
    I'm not sure if I'm reading your response correctly or not, but I would definitely not refactor java.beans.Statement just to get this problem solved with out editing files ... ... since java.sql.Statement is used so widely, perhaps they should have considered a different name for java.beans.Statement , although you hate to base a name off of what's going to cause the least problems, rather then what makes the most sense ... ... any way, I guess it doesn't matter now: the name has been selected .... I'd be interested to hear how you solved the problem.

  • Java Bean Connectivity and Closing Connections (XI 3.0)

    Hi guys,
    We have existing Java Beans that we would like to use with Crystal Reports. Our current Java beans return a disconnected GridModel and explicitly close the connection immediately after so that they can be returned to the connection pool (Oracle).
    Once we modified these beans to return ResultSets we found that closing the connection also closes all the associated ResultSets and Statements.
    What is the best practice here?
    Modify the Java bean to close the connection in the finally block?
    Will Crystal clean up after itself?
    I also see there is something called a CachedRowSet which is disconnected:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html
    Is this supported by Crystal?
    Thanks,
    Kevin D Lee =)

    Hello Kevin,
    Enterprise XI 3.0 CRConfig.xml points to Java JRE 1.5 provided with the install, so you should be ok with the CachedRowSet. 
    It's used by other customers for disconnected operation.
    Since you're going to Oracle, you'd likely encounter issues mapping Oracle fields to POJO property types.
    Furthermore, POJO Factory libraries that were shipped with Crystal Reports XI Release 2 aren't shipped with Enterprise XI 3.0, so you'd not find that an out-of-the-box option. 
    Another alternative to CachedRowSet is to define callback method in your JavaBeans class that Crystal will call when it's done with the data source. 
    This has been implemented in XI 3.0 (track ADAPT00877915) - excerpt from the track note:
    <JavaBeans>
        <CacheRowSetSize>100</CacheRowSetSize>
         <JavaBeansClassPath>c:\javabeans\</JavaBeansClassPath>
         <CallBackFunction>CrystalReportsLogoff</CallBackFunction>
    </JavaBeans>
          Customer can configuration the <CallBackFunction/> to let CR know
          which function should be invoked when loging off.
    Advantage of CachedRowSet is that you can immediately close it after you've read all the data, disadvantage would be the default implementation stores all data in memory.
    Advantage of the callback method is that it would use the JavaBean you've supplied (and not load all data immediately in memory), but callback won't be called immediately, but only after the report is done with.
    Sincerely,
    Ted Ueda

  • Column Not found error while trying to access databse through JSP+Java Bean

    I am trying to acees MS Access 2003 db through JSP using Tomcat 5.0.28.The code for accessing the databse is incorporated in the bean.The jsp only calls the particular method of the bean .
    Code for Java Bean:
    package ActiveViewer;
    import java.sql.*;
    import java.util.*;
    public class CompanyBean
    Connection con;
    ResultSet rs=null;
    Statement st;
         public CompanyBean(){}
         public void connect()
         try
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("Here4");
    con=DriverManager.getConnection("jdbc:odbc:activeviewer","","");
         System.out.println("Here1");
         catch (ClassNotFoundException e)
         System.out.println("Could not locate driver.");
    catch (SQLException e)
    System.out.println("An SQL Exception has occured :: "+e);
         e.printStackTrace();
         catch (Exception e)
    System.out.println("An unknown Exception has occured :: "+e);
         e.printStackTrace();
    public void disconnect()
         try
         if (con!=null)
    con.close();
         catch (SQLException e)
    System.out.println("An SQL Exception has occured :: "+e);
         e.printStackTrace();
    public ResultSet select(String username)
    if(con!=null)
         try
    st=con.createStatement();
         rs=st.executeQuery("select * from company where username='" + username + "'");
    catch (SQLException e)
    System.out.println("An SQL Exception has occured :: "+e);
         e.printStackTrace();
    catch (Exception e)
    System.out.println("An Exception has occured while retrieving :: "+e);
    e.printStackTrace();
    else
    System.out.println("Connection to database was lost.");
    return rs;
    The code for JSP that uses the above bean is:
    <%@ page language="java" import="java.sql.*,ActiveViewer.* " contentType="text/html"%>
    <jsp:useBean id="conn" scope="session" class="ActiveViewer.CompanyBean" />
    <html>
    <body>
    <% String username=request.getParameter("username");
    String password=request.getParameter("password");
    System.out.println("username:"+username);
    System.out.println("password:"+password);
    conn.connect();
    ResultSet rs=conn.select(username);
    System.out.println("Below select ");
    while (rs.next())
    String dbusername=rs.getString("username");
         String dbpassword=rs.getString("password");
         if(dbusername.equals(username) && dbpassword.equals (password))
    { %> out.println("OK");
              <% }
    else { %>Invalid Username and / or Password.
    <br>Clickhere to go back to Login Page.
    <% }
    } %>
    </body>
    </html>
    I get the following error:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Column not found
    though the database is not int he same folder as the jsp, the DSN is set correctly to pint to the db location.The jsp does print in stdout file:
    Here4 (from connect method above)
    Here 1 (from connect method above)
    Below Select (from jsp)
    This means that the jsp does connect to db but it gives the above error.Also the field name also matches that in the database and data is present in the db too.
    All other things like creating package for bean,incorporating the packakage are done.
    Can someone please help me with their precious advice?

    U're getting this error because there is no field called 'password' in ur database, the field in ur database is named 'cpassword' and not 'password'. So change the statement rs.getString("password"); to rs.getString("cpassword");

  • "Java-Bean: True" missing after being packed in jar file

    Hi All
    X86, Windows XP Professional, J2SDK 1.4.2
    I complied a section of code ", which is from << Thinking In Java>>(3rd).
    Created a manifest file "BangBean.tmp"
    <<
    Name: bangbean/BangBean.class
    Java-Bean: True
    >>
    And then packed class files into "BangBean.jar" with command
    "jar cfm BangBean.jar Bang BangBean.tmp bangbean".
    It's puzzling that "Java-Bean: Ture" was missing in the "BangBean.jar/META-INF/MENIFEST.MF" .
    <<
    Manifest-Version: 1.0
    Created-By: 1.4.2 (Sun Microsystems Inc.)
    Name: bangbean/BangBean.class
    >>
    What's more, after altering the"BangBean.tmp" into this
    <<
    Java-Bean: True
    Name: bangbean/BangBean.class
    >>
    and had a another try.
    I got a jar file with such MENIFEST.MF.
    <<
    Manifest-Version: 1.0
    Created-By: 1.4.2 (Sun Microsystems Inc.)
    Java-Bean: True
    Name: bangbean/BangBean.class
    >>
    This jar file worked well in BDK's beanbox.
    I've test it with JSDK 1.5.0, the same thing happened.
    And I didn't encounter such problem in other bean programs.
    I've searched " 'Java-Bean: True' missing " with google, but didn't get proper answers.
    Is there anybody who can give a prompt about why this happend?
    Thanks a lot for your help!
    code
    //: bangbean:BangBean.java
    // A graphical Bean.
    package bangbean;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import com.bruceeckel.swing.*;
    public class
    BangBean extends JPanel implements Serializable {
    private int xm, ym;
    private int cSize = 20; // Circle size
    private String text = "Bang!";
    private int fontSize = 48;
    private Color tColor = Color.RED;
    private ActionListener actionListener;
    public BangBean() {
    addMouseListener(new ML());
    addMouseMotionListener(new MML());
    public int getCircleSize() { return cSize; }
    public void setCircleSize(int newSize) {
    cSize = newSize;
    public String getBangText() { return text; }
    public void setBangText(String newText) {
    text = newText;
    public int getFontSize() { return fontSize; }
    public void setFontSize(int newSize) {
    fontSize = newSize;
    public Color getTextColor() { return tColor; }
    public void setTextColor(Color newColor) {
    tColor = newColor;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.BLACK);
    g.drawOval(xm - cSize/2, ym - cSize/2, cSize, cSize);
    // This is a unicast listener, which is
    // the simplest form of listener management:
    public void addActionListener(ActionListener l)
    throws TooManyListenersException {
    if(actionListener != null)
    throw new TooManyListenersException();
    actionListener = l;
    public void removeActionListener(ActionListener l) {
    actionListener = null;
    class ML extends MouseAdapter {
    public void mousePressed(MouseEvent e) {
    Graphics g = getGraphics();
    g.setColor(tColor);
    g.setFont(
    new Font("TimesRoman", Font.BOLD, fontSize));
    int width = g.getFontMetrics().stringWidth(text);
    g.drawString(text, (getSize().width - width) /2,
    getSize().height/2);
    g.dispose();
    // Call the listener's method:
    if(actionListener != null)
    actionListener.actionPerformed(
    new ActionEvent(BangBean.this,
    ActionEvent.ACTION_PERFORMED, null));
    class MML extends MouseMotionAdapter {
    public void mouseMoved(MouseEvent e) {
    xm = e.getX();
    ym = e.getY();
    repaint();
    public Dimension getPreferredSize() {
    return new Dimension(200, 200);
    } ///:~
    ************************************************

    Since you didn't use code-formatting tags ([ code ] and [ /code ] without the spaces) it's kinda hard to look at it. But I'm sure it DID execute much more than just the return statement - maybe you're not closing a file or db connection, or maybe you're seeing a cached page, so it actually isn't executing ANYTHING on the server (is your browser set to never check for newer pages so it (almost) always returns from cache, for example?)

  • Help required in building up the Java Bean for an XML data

    Hi ,
    I want to build a Java bean which will actually represent an xml data . The class will be named as User and it will typically represent the data in the follwing xml:
    <user>
    <cwsId>barbete</cwsId>
    <firstName>William</firstName>
    <lastName>Barber</lastName>
    <status>true</status>
    <role>
    <roleCode>1000000177</roleCode>
    <roleName>Customer Administrator</roleName>
    </role>
    <language>en</language>
    <country>US</country>
    <preferences>
    <equipmentGroup>2717</equipmentGroup>
    <dateFormat>MON-dd-yyyy</dateFormat>
    <timeFormat>HH:MI AM</timeFormat>
    <timeZone>-12:00</timeZone>
    <daylightSavings>Y</daylightSavings>
    <location>NC</location>
    <recordsPerPage>10</recordsPerPage>
    <historyPeriod>3</historyPeriod>
    <distanceUnit>MILE</distanceUnit>
    <fuelUnit>G</fuelUnit>
    <unitIdDisplay>E</unitIdDisplay>
    <smuUpdate>W</smuUpdate>
    <countries>
    <country>
    <countryCode>GB</countryCode>
    <countryName>UNITED KINGDOM</countryName>
    </country>
    <country>
    <countryCode>US</countryCode>
    <countryName>UNITED STATES</countryName>
    </country></countries>
    </preferences>
    </user>
    Now for single child nodes like cwsId of the main user node i have kept properties like
    private String cwsId;
    But i am not sure as to how to represent the nodes which contain subnodes like "preferences"node. Any ideas?What is the standard practice?

    One thing you could do is create an object model first, which will contain all the data for your user.
    then all you need in the bean is a Hashtable with the name of the user as a key, and the user-object (which is actually the complete object model) as a value.
    with the XML stated by you, you would get an object model something like this:
    Class User
        String cwsid;
        String firstName;
        ArrayList<Role> roles = new ArrayList<Role>(); //I'm assuming a user can have more then one role.
        ArrayList<Country> countries = new ArrayList<Country>();
    class Role {
        String code;
        String name;
    class Country {
        String code;
        String name;
    }And so on for all the varioous elemets of your XML.

  • Using Java Bean in JSP to show database record

    I have links in my Tomcat container that if someone clicks on a specific link it should go to a Record page (Show.jsp) with all the values associated with a record from a database.
    For example if someone clicks on a specific link like this:
    LinkExample
    it would take you to a jsp with database info for someone named Jones and show you his info:
    Lastname = Jones
    Firstname = Mike
    City = San Diego
    I would like to do this using a Java helper class and bean so I dont have any database connection or Java code in my JSP.
    I created Java class file that has Database connection that works with a Java bean. I just dont know how to get the Show.jsp to work with the Java Bean and Java helper class file.
    Here is what I have for Show.jsp and this is the part I have been working on the longest but cant get it to work because it doesnt seem to work with the database:<jsp:useBean id="user" class="num.UserDB"/>
    //do I call getUser(lastname) here and if so how?
    <jsp:setProperty name="user" property="*"/>
    Last Name: <jsp:getProperty name="user" property="lastname"/><BR>
    First Name: <jsp:getProperty name="user" property="firstname"/><BR>
    City: <jsp:getProperty name="user" property="city"/><BR>My Java Helper class that compiles and connects to database:
    package num;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import num.User;
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName...//database connection stuff here
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
            user.setFirstname(results.getString("city"));
         catch(Exception e)          
                   System.out.println("Exception...");               
       return user;
    }My Java Bean that compiles here:
    package num;
    public class User
      private String firstname;
      private String lastname;
    private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, String city)
           this.lastname = lastname;
              this.firstname = firstname;
              this.city = city;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      //more bean methods for all fields here
     

    Sorry if I wasnt specific enough. I have a link that passes a value (field that is passed is called lastname) to a JSP where I want to show record info for that value that is passed.
    My question is how do I show the database record info on Show.jsp for the lastname field value of Jones where I want to use a Java Bean and Database helper class in Show.jsp
    Here is the message I get when I hit the link (LinkExample) and it goes to Show.jsp:
    org.apache.jasper.JasperException: Cannot find any information on property 'lastname' in a bean of type 'num.UserDB'
    .....My UserDB class:
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName("org.gjt.mm.mysql.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/dbconnone?user=smitherson&password=abcdefg");
        Statement stmt = conn.createStatement();
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
                         user.city(results.getString("city"));
         catch(Exception e)          
             System.out.println("Exception..." + e);          
       return user;
    }Bean class:
    package num;
    public class User
      private String firstname;
      private String lastname;
      private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, Sting city)
          this.firstname = firstname;
           this.lastname = lastname;
    this.city = city;
      public String getFirstname()
              return firstname;
      public void setFirstname(String firstname)
         this.firstname = firstname;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      public String getCity()
              return city;
      public void setCity(String city)
         this.city = city;
      

  • Help with Login Form (JSP DB Java Beans Session Tracking)

    Hi, I need some help with my login form.
    The design of my authetication system is as follows.
    1. Login.jsp sends login details to validation.jsp.
    2. Validation.jsp queries a DB against the parameters received.
    3. If the query result is good, I retrieve some information (login id, name, etc.) from the DB and store it into a Java Bean.
    4. The bean itself is referenced with the current session.
    5. Once all that's done, validation.jsp forwards to main.jsp.
    6. As a means to maintain state, I prefer to use url encoding instead of cookies for obvious reasons.I need some help from step 3 onwards please! Some code snippets will do as well!
    If you think this approach is not a good practice, pls let me know and advice on better practices!
    Thanks a lot!

    Alright,here is an example for you.
    Assume a case where you don't want to give access to any JSP View/HTML Page/Servlet/Backing Bean unless user logging system and let assume you are creating a View Object with the name.
    checkout an example (Assuming the filter is being applied to a pattern * which means when a resource is been accessed by webapplication using APP_URL the filter would be called)
    public doFilter(ServletRequest req,ServletResponse res,FilterChain chain){
         if(req instanceof HttpServletRequest){
                HttpServletRequest request = (HttpServletRequest) req;
                HttpSession session = request.getSession();
                String username = request.getParameter("username");
                String password = request.getParameter("password");
                String method = request.getMethod();
                String auth_type  = request.getAuthType();
                if(session.getAttribute("useInfoBean") != null)
                    request.getRequestDispatcher("/dashBoard").forward(req,res);
                else{
                        if(username != null && password != null && method.equaIsgnoreCase("POST") && (auth_type.equalsIgnoreCase("FORM_AUTH") ||  auth_type.equalsIgnoreCase("CLIENT_CERT_AUTH")) )
                             chain.doFilter(req,res);
                        else 
                          request.getRequestDispatcher("/Login.jsp").forward(req,res);
    }If carefully look at the code the autherization is given only if either user is already logged in or making an attempt to login in secured way.
    to know more insights about where these can used and how these can be used and how ?? the below links might help you.
    http://javaboutique.internet.com/tutorials/Servlet_Filters/
    http://e-docs.bea.com/wls/docs92/dvspisec/servlet.html
    http://livedocs.adobe.com/jrun/4/Programmers_Guide/filters3.htm
    http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html
    http://www.servlets.com/soapbox/filters.html
    http://www.onjava.com/pub/a/onjava/2001/05/10/servlet_filters.html
    and coming back to DAO Pattern hope the below link might help you.
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    http://java.sun.com/blueprints/patterns/DAO.html
    http://www.javapractices.com/Topic66.cjp
    http://www.ibm.com/developerworks/java/library/j-dao/
    http://www.javaworld.com/javaworld/jw-03-2002/jw-0301-dao.html
    On the whole(:D) it is always a good practice to get back to Core Java/J2EE Patterns.and know answers to the question Why are they used & How do i implement them and where do i use it ??
    http://www.fluffycat.com/java-design-patterns/
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html
    http://www.cmcrossroads.com/bradapp/javapats.html
    Hope that might help :)
    REGARDS,
    RaHuL

  • How can I insert a record through a java bean

    Hi everybody,
    I'd some problem when I insert a record using java bean. When I want to insert a record. The result in executeUpdate must return 0. Would you please tell me what's wrong in my code?
    java bean
    package miniproj;
    import java.sql.*;
    public class Register{
         private String sql;
         private String username;
         private String usertype;
         private String password;
         private String blocknum;
         private int floornum;
         private String owner;
         private int rows;
         private String s;
    // set parameter to database
         public int setMember(){
              try{
    //load database driver
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    // Get a connection to the database
                   Connection sqlConn = java.sql.DriverManager.getConnection("jdbc.odbc:WFBS");
    // Get a statement from the connection
                   Statement sqlStmt = sqlConn.createStatement();
                   sql = "INSERT INTO USERS(user_name, password) VALEUS ('aaa', 'aaa')";
    //               sql = "INSERT INTO USERS(user_name, password) VALEUS (" + user_name + "," + password + ")" ;
                   rows = sqlStmt.executeUpdate(sql);
    //               sqlRst.close();
                   sqlStmt.close();
                   sqlConn.close();
              catch(SQLException se){
              catch(Exception e){
              return rows;
    // set user name method
         public void setUsername(String name){
              username = name;
    // set passwrod method
         public void setPassword(String pwd){
              password = pwd;
    // set block num mehtod
         public void setBlockNum(String block){
              blocknum = block;
    // set floor num method
         public void setFloorNum(int floor){
              floornum = floor;
    // set owner method
         public void setOnwer(String own){
              owner = own;
    // get user name method
         public String getUsername(){
              return username;
    // get password method
         public String getPassword(){
              return password;
    jsp code
    <%@ include file="Header.jsp" %>
    <%@ page errorPage="Error.jsp" %>
    <jsp:useBean id="register" class="miniproj.Register" />
    <jsp:setProperty name="register" property="*" />
    User name : <%=register.getUsername()%><br>
    Password : <%=register.getPassword()%><br>
    <%
         int i = register.setMember();
         out.println(i);
    %>
    Thanks a lot
    Chris

    Correct the spelling of Values
    sql = "INSERT INTO USERS(user_name, password) VALUES ('aaa', 'aaa')";

  • User parameter are not show in database using Servlet and java Bean

    Hello Sir,
    when I insert the parameter in run time, weblogic server and JSP show that parameter are saved.
    Allthough row increment in database but they not show in database.
    Here My Code:
    login.html:
    <html>
    <head>
    <title>A simple JSP application</title>
    <head>
    <body>
    <form method="get" action="tmp" >
    Name: <input type="text" name="user">
    Password: <input type="password" name="pass">
    <input type="Submit" value="Submit">
    </form>
    </body>
    </html>LoginServlet.java:import javax.servlet.*;
    import javax.servlet.http.*;
    public class LoginServlet extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{
    try
    String user=request.getParameter("user");
    String pass=request.getParameter("pass");
    co.SimpleBean st = new co.SimpleBean();
    st.setuserName(user);
    st.setpassword(pass);
    request.setAttribute("user",st);
    request.setAttribute("pass",st);
    RequestDispatcher dispatcher1 =request.getRequestDispatcher("submit.jsp");
    dispatcher1.forward(request,response);
    catch(Exception e)
    e.printStackTrace();
    }SimpleBean.java:
    package co;
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.util.*;
    public class SimpleBean {
    private String user="";
    private String pass="";
    private String s="";
    public String getuserName() {
    return user;
    public void setuserName(String user) {
    this.user = user;
    public String getpassword() {
    return pass;
    public void setpassword(String Pass) {
    this.pass= pass ;
    public String issueData()
    try
    System.out.println("Printed*************************************************************");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("Connection loaded");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@VijayKumar-PC:1521:XE","SYSTEM","SYSTEM");
    System.out.println("Connection created");
    PreparedStatement st=con.prepareStatement("insert into vij2 values(?,?)");
    System.out.println("~~~~~~~~~~~~~~~~~~~~");
    String NAME=getuserName();
    st.setString(1,NAME);
    String PASSWORD=getpassword();
    st.setString(2,PASSWORD);
      st.executeUpdate();
    System.out.println("Query Executed");
    con.close();
    s=  "Your logging is saved in DB ";
    System.out.println("Your logging is saved in DB *****************");
    return(s);
    catch(Exception e)
    e.printStackTrace();
    return "failed";
    }submit.jsp:This is Submit page
    <jsp:useBean id="st" class="co.SimpleBean"/>
    <jsp:setProperty name="st" property="*" />
    <jsp:getProperty name="st" property="userName" /> <br>
    <jsp:getProperty name="st" property="password" /> <br>
    <% st.issueData();%>
    <%
    out.println("Ur data is saved in DB");
    %>Please Help me.
    Thanks.

    Ok, this seems to be a long and convoluted path to do absolutely nothing.
    You submit the form.
    You run a servlet that gets the parameters correctly (good), creates a SimpleBean (good) and then sets this into request attribute space under the names "user" and "pass" - (why?)
    You then forward to the jsp: submit.jsp.
    Submit.jsp creates a new SimpleBean, and attempts to populate it with <jsp:setProperty>. You then call the issueData method on it.
    Your complaint: Rows are being created in the database which have empty string values instead of the parameters you have passed.
    So, why are the values blank? Where do you think these values should be coming from?
    Looking at SimpleBean we find one mistake - you have mis-named your get/set methods.
    To properly follow java beans standards, you should use camel-case for your methods.
    Rather than getuserName() the method should be getUserName(). getpassword() should be getPassword() etc etc.
    The method getUserName() defines a property "userName" for the bean.
    Once that is fixed, lets go to submit.jsp. The <jsp:setProperty> statement will try and set all properties of the bean from the request parameters.
    There are no request parameters "userName" or "password" so those values don't get set in the bean, therefore it uses their default value of empty string - "".
    There ARE request parameters called "user" and "pass" but because they aren't properties of the bean, they get ignored.
    As a result, the values are empty string, and that is exactly what gets inserted into the database.
    Ways to fix this
    1 - rename your parameters on your form to be "userName" and "password" to match the bean. That way the <jsp:setProperty> tag will populate them properly.
    or
    2 - Call issueData() method from your servlet after you have created the SimpleBean. Better in my opinion as you then don't have any scriptlet code on a JSP page.
    Cheers,
    evnafets

  • Calling Java Bean From JSP

    <%@ page contentType="text/html;charset=windows-1252" errorPage = "error.jsp"%>
    <%@ page import="java.sql.*,java.io.*,javax.sql.*, mypackage1.*"%>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>Process</title>
      </head>
      <body>
          <P align="center">
            <STRONG><FONT face="Algerian" size="6" color="#0033cc">Result from the Query</FONT></STRONG>
          </P>
          <P align="center"> </P>
          <P align="center"> </P>
          <P align="center"> </P>
          <P align="center"> </P>
          <P align="center">
       <%
            int rowsChanged;
            Connection con;
            try
              String sql;
              sql = request.getParameter("query");
              System.out.println(sql);
              session=request.getSession(true);
              String name = (String)session.getAttribute("theID");
              String password = (String)session.getAttribute("paswd");
              String driver="oracle.jdbc.OracleDriver";
              Class.forName(driver);
              String url ="jdbc:oracle:thin:@minerva.humber.ca:1521:grok" ;      
              con = DriverManager.getConnection(url,name,password);
              if(sql.substring(0,6).equalsIgnoreCase("Select"))
                  Statement stat = con.createStatement();
                     ResultSet rs = stat.executeQuery(sql);
          %>
         <jsp:useBean id="myBean" scope="page" class="mypackage1.Table" >
               </jsp:useBean>
             <jsp:setProperty name="myBean" property="*" param="<%rs%>"/>
          <%
            myBean.setTable(rs);
            out.println(myBean.getTable());
         %>
          <%
           else
              Statement stat = con.createStatement();
              rowsChanged = stat.executeUpdate(sql);
              out.println("<h3><STRONG><FONT face=Algerian size=5 color=#0033cc>Number of rows affected are: "+rowsChanged+"</h3></Strong></Font>");
           }//End of Try
           catch(Exception e)
              System.out.println(e+ "gd"+ e.getMessage());     
          %>
          </P>
            <P align="center">
            <a href="check.jsp">Please Click Here to Return to Main Page</a>
          </P>
      </body>
    </html>Above is my JSP file, which is calling a Java bean class called Table. The thing is that Its not returning any Table from the Table Class. I dont know how to use Java bean as I m new to it. Following is my Table Class. So If anyone can plz help me then it would be great. I m suffering from 2 days just because of this class and JSP.
    package mypackage1;
    import java.io.Serializable;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    public class Table implements Serializable
      private ResultSet rs;
      public Table()
      public void setTable(ResultSet result)
        rs = result;
      public String getTable()
             String output=null;
             try
                    ResultSetMetaData metadata;
                    metadata=rs.getMetaData();
         // find the number of fields in customer table
                    int col=metadata.getColumnCount();
                    output = "<table/><tr/>";
                    for(int i=1;i<=col;i++)
                        output+="<td/><b/>"+metadata.getColumnName(i)+"</b/></td/>";
                    output += "</tr/>";
                    while (rs.next())
                           output="<tr/>";
                           for(int i=1;i<=col;i++)
                             output+="<td/>"+rs.getString(i)+"</td/>";
                           output += "</tr/></table/>";
                    }//End of While
               catch(Exception e)
        return output;
      }//End of Table method
    }//End of Class

    First reaction: yuck.
    This is not something you should be using a bean for.
    Beans are meant for storing data, not for generating HTML from.
    I don't really like queries on a JSP page either, but thats a different story again.
    I would recommend you use JSTL for this.
    1 - it provides a c:forEach tag for looping
    2 - it provides sql tags for doing queries in a database
    IF you are going to do database queries from a JSP page, I absolutely recommend you use the JSTL tags.
    (end rant)
    Your problem is probably caused by the fact that in your bean you have the following
    try{
      // code here
    catch (Exception e){
      // completely ignore exception and carry on as if nothing bad happened.
      // what you should be doing is something like:
      System.out.println("Error occurred " + e.getMessage());
      e.printStackTrace();
      return e.getMessage();
    }Cheers,
    evnafets

  • Question about main difference between Java bean and Java class in JSP

    Hi All,
    I am new to Java Bean and wonder what is the main difference to use a Bean or an Object in the jsp. I have search on the forum and find some post also asking the question but still answer my doubt. Indeed, what is the real advantage of using bean in jsp.
    Let me give an example to illustrate my question:
    <code>
    <%@ page errorPage="errorpage.jsp" %>
    <%@ page import="ShoppingCart" %>
    <!-- Instantiate the Counter bean with an id of "counter" -->
    <jsp:useBean id="cart" scope="session" class="ShoppingCart" />
    <html>
    <head><title>Shopping Cart</title></head>
    <body bgcolor="#FFFFFF">
    Your cart's ID is: <%=cart.getId()%>.
    </body>
    <html>
    </code>
    In the above code, I can also create a object of ShoppingCart by new operator then get the id at the following way.
    <code>
    <%
    ShoppingCart cart = new ShoppingCart();
    out.println(cart.getId());
    %>
    </code>
    Now my question is what is the difference between the two method? As in my mind, a normal class can also have it setter and getter methods for its properties. But someone may say that, there is a scope="session", which can be declared in an normal object. It may be a point but it can be easily solved but putting the object in session by "session.setAttribute("cart", cart)".
    I have been searching on this issue on the internet for a long time and most of them just say someting like "persistance of state", "bean follow some conventions of naming", "bean must implement ser" and so on. All of above can be solved by other means, for example, a normal class can also follow the convention. I am really get confused with it, and really want to know what is the main point(s) of using the java bean.
    Any help will be highly apprecaited. Thanks!!!
    Best Regards,
    Alex

    Hi All,
    I am new to Java Bean and wonder what is the main
    difference to use a Bean or an Object in the jsp. The first thing to realize is that JavaBeans are just Plain Old Java Objects (POJOs) that follow a specific set of semantics (get/set methods, etc...). So what is the difference between a Bean and an Object? Nothing.
    <jsp:useBean id="cart" scope="session" class="ShoppingCart" />
    In the above code, I can also create a object of
    ShoppingCart by new operator then get the id at the
    following way.
    ShoppingCart cart = new ShoppingCart();
    out.println(cart.getId());
    ...Sure you could. And if the Cart was in a package (it has to be) you also need to put an import statement in. Oh, and to make sure the object is accessable in the same scope, you have to put it into the PageContext scope. And to totally equal, you first check to see if that object already exists in scope. So to get the equivalant of this:
    <jsp:useBean id="cart" class="my.pack.ShoppingCart"/>Then your scriptlet looks like this:
    <%@ page import="my.pack.ShoppingCart %>
    <%
      ShoppingCart cart = pageContext.getAttribute("cart");
      if (cart == null) {
        cart = new ShoppingCart();
        pageContext.setAttribute("cart", cart);
    %>So it is a lot more work.
    As in my mind, a normal class can also
    have it setter and getter methods for its properties.True ... See below.
    But someone may say that, there is a scope="session",
    which can be declared in an normal object.As long as the object is serializeable, yes.
    It may be
    a point but it can be easily solved but putting the
    object in session by "session.setAttribute("cart",
    cart)".Possible, but if the object isn't serializable it can be unsafe. As the point I mentioned above, the useBean tag allows you to check if the bean exists already, and use that, or make a new one if it does not yet exist in one line. A lot easier than the code you need to use otherwise.
    I have been searching on this issue on the internet
    for a long time and most of them just say someting
    like "persistance of state", "bean follow some
    conventions of naming", "bean must implement ser" and
    so on. Right, that would go along the lines of the definition of what a JavaBean is.
    All of above can be solved by other means, for
    example, a normal class can also follow the
    convention. And if it does - then it is a JavaBean! A JavaBean is any Object whose class definition would include all of the following:
    1) A public, no-argument constructor
    2) Implements Serializeable
    3) Properties are revealed through public mutator methods (void return type, start with 'set' have a single Object parameter list) and public accessor methods (Object return type, void parameter list, begin with 'get').
    4) Contain any necessary event handling methods. Depending on the purpose of the bean, you may include event handlers for when the properties change.
    I am really get confused with it, and
    really want to know what is the main point(s) of
    using the java bean.JavaBeans are normal objects that follow these conventions. Because they do, then you can access them through simplified means. For example, One way of having an object in session that contains data I want to print our might be:
    <%@ page import="my.pack.ShoppingCart %>
    <%
      ShoppingCart cart = session.getAttribute("cart");
      if (cart == null) {
        cart = new ShoppingCart();
        session.setAttribute("cart", cart);
    %>Then later where I want to print a total:
    <% out.print(cart.getTotal() %>Or, if the cart is a JavaBean I could do this:
    <jsp:useBean id="cart" class="my.pack.ShoppingCart" scope="session"/>
    Then later on:
    <jsp:getProperty name="cart" property="total"/>
    Or perhaps I want to set some properties on the object that I get off of the URL's parameter group. I could do this:
    <%
      ShoppingCart cart = session.getAttribute("cart");
      if (cart == null) {
        cart = new ShoppingCart();
        cart.setCreditCard(request.getParameter("creditCard"));
        cart.setFirstName(request.getParameter("firstName"));
        cart.setLastName(request.getParameter("lastName"));
        cart.setBillingAddress1(request.getParameter("billingAddress1"));
        cart.setBillingAddress2(request.getParameter("billingAddress2"));
        cart.setZipCode(request.getParameter("zipCode"));
        cart.setRegion(request.getParameter("region"));
        cart.setCountry(request.getParameter("country"));
        pageContext.setAttribute("cart", cart);
        session.setAttribute("cart", cart);
      }Or you could use:
    <jsp:useBean id="cart" class="my.pack.ShoppingCart" scope="session">
      <jsp:setProperty name="cart" property="*"/>
    </jsp:useBean>The second seems easier to me.
    It also allows you to use your objects in more varied cases - for example, JSTL (the standard tag libraries) and EL (expression language) only work with JavaBeans (objects that follow the JavaBeans conventions) because they expect objects to have the no-arg constuctor, and properties accessed/changed via getXXX and setXXX methods.
    >
    Any help will be highly apprecaited. Thanks!!!
    Best Regards,
    Alex

  • Java Connectivity - No classes appearing in the Java Beans Classes dropdown

    Hi,
    VERY NEW user to Crystal Reports.  I am trying to create a report using a java class as a datasource.  I have updated the setting in the CRConfig.xml file, and can get the Java Beans Connectivity screen to appear, but is shows none of my classes in the dropdown.  I found a knowlege base entry that indicated this problem was caused by the JavaBeansClassPath value in the CRConfig.xml file being invalid.  But I've verified the location and it is pathed directly to the classes.
    Not sure what I am missing, but any help is greatly appreciated.
    Thanks!

    Ted,
    Thanks for the reply.  I checked out each of your suggestions, but haven't had any luck thus far.  Here's what I found:
    1.  We created a simple method in an existing public class to return a ResultSet.  The method looks like this:
    public ResultSet GetAllMediaTypesRS()
          String strFuncName = "ScsXDMDatabase::GetAllMediaTypesRS : ";
          ScsDebug coutDebug = new ScsDebug();
          String strSqlStmt;
          String strMediaType;
          ScsStringList sslReturnList = new ScsStringList();
          // Create the SQL to get all the Displayable Media Types.
          strSqlStmt =
             "SELECT DISTINCT mt.Media_Type_Name "
                + "FROM dbo.Media_Type mt "
                + "WHERE mt.Media_Type_Rqst_Display_Ind = 1 "
                + "ORDER BY mt.Media_Type_Name";
          coutDebug.println(strFuncName + "SQL Statement:  " + strSqlStmt);
          // Run the Query
          Statement stmt = null;
          ResultSet SQLResult = null;
          try
             stmt = GetConnection().createStatement();
             SQLResult = stmt.executeQuery(strSqlStmt);
          } //End of Try
          catch (SQLException sqle)
             if (sqle.getErrorCode() != 0)
                coutDebug.println(
                   "Error in ExecuteQuery: "
                      + "Error code - "
                      + sqle.getErrorCode());
                coutDebug.println("Message - " + sqle.getMessage());
          return SQLResult;
    The signature, and the method look fine to us, but maybe we are missing something obvious.
    2. We do use JDK 1.5 to compile the classes, but my JavaDir setting in the CRConfig.xml file points to jre1.6.0_02.  I assume this is OK.
    3. We do see java.exe start up when opening the JavaBeans connection.
    4. No firewall issues as we are inside our corporate network.
    Any other thoughts or ideas?  I did see a knowledge base entry that indicated the cause of this particular problem is that the JavaBeansClassPath in CRConfig.xml is incorrect or invalid.  I've validated the path takes me right to the classes, so I believe that is OK.  Is there some way that we can see the actual path that is searched when the JavaBeans connection is opened?
    Thanks for your help.
    --john davies

  • Java Beans

    hai,
    i have a web application and i use bean to do the database operations...i like to use a configuration file where i can store the database connection parameters like hostname, username and password so that i can change them without recompiling the java files ...i put file db.cfg in the /WEB-INF/classes directory but tomcat gives error message as file not found..please help with a complete code...
    here is the code i used...
    public ResultSet getdata(String sql){
              try{
    File f1 = new File("db.cfg");
    FileInputStream fstream = new FileInputStream(f1);
    DataInputStream inD = new DataInputStream(fstream);
    String[] s3=new String[3];
    int i=0;
    while (i<3)
                             s3=inD.readLine();
                             i++;
                   inD.close();
                   //db.cfg end
                   String name=s3[0];
                   String password=s3[1];
                   String url=s3[2];
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection(url,name,password);
    Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                   rs=st.executeQuery(sql);
              }catch(Exception e){
                   System.out.println("from getdata"+e);
              return rs;

    Hi,
    Please check out the location http://technet.oracle.com/products/developer/
    There is a document
    "Using Java Components in Oracle Developer Applications"
    This document provides the
    information on 'using JavaBeans in Forms',
    Regards,
    Deepak Rai
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by vinayak prabhu ([email protected]):
    How do we use Java beans in forms 6.0 ?
    Please help.
    Thanks.
    (Vinayak Prabhu)
    Vinny.<HR></BLOCKQUOTE>
    null

  • URGENT! Java Bean Query

    I am using Tomcat 3.1 and MySQL database for an application I am designing. Below is the code for a java bean that registers users details. The code compiles correctly, but I would like to know if there is any code that I might have left out? What changes should I make to make it more user friendly?
    I do not want to use servlets, as they are very difficult to setup.
    REGISTRATION.JAVA
    package gcd;
    import java.sql.*;
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.text.*;
    import java.io.*;
    import com.mysql.jdbc.*;
    public class Registration
         public Registration(){}
    String first_name;
    String last_name;
    String role;
    String email;
    String error;
    java.sql.Connection con;
    public void setFirstName( String value )
    first_name = value;
    public void setLastName( String value )
    last_name = value;
    public void setRole( String value )
    role = value;
    public void setEmail( String value )
    email = value;
    public String getFirstName()
    return first_name;
    public String getLastName()
         return last_name;
    public String getRole()
         return role;
    public String getEmail()
         return email;
         public void connect() throws ClassNotFoundException, SQLException, Exception
    try
    System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://localhost/gcdBB_db","","");
    catch (ClassNotFoundException e)
    error = "ClassNotFoundException: Could not locate DB driver.";
    throw new ClassNotFoundException(error);
    catch (SQLException e)
    error = "SQLException: Could not connect to database.";
    throw new SQLException(error);
    catch (Exception e)
    error = "Exception: An unknown error occured while connecting to database.";
    throw new Exception (error);
         public void disconnect() throws SQLException
    try
    if(con != null)
    con.close();
    catch (SQLException e)
    error = ("SQLException: Unable to close the database connection.");
    throw new SQLException(error);
    public java.sql.ResultSet validateRegistration(String firstname, String lastname, String role, String email) throws SQLException, Exception
    java.sql.ResultSet rs = null;
    try
    String queryString = ("INSERT INTO registration (firstname,lastname,role,email) VALUES ('" + firstname + "','" + lastname + "','" + role + "','" + email + "';");
    java.sql.Statement stmt = con.createStatement();
    rs = stmt.executeQuery(queryString);
    catch (SQLException e)
    error = "SQLException: Could not execute the query.";
    throw new SQLException(error);
    catch (Exception e)
    error = "An exception occured while retrieving users.";
    throw new Exception(error);
    return rs;
    Thanks,
    Niall

    in JavaBean class:
    The setting/getting method should be matched with the first letter capitalized. ie.
    String firstName;
    String lastName;
    public void setFirstName(String value) { firstName = value ; }
    public String getFirstName() { return firstName; }
    public void setLastName(String value) { lastName = value ; }
    public String getLastName() { return lastName; }
    String role and email coded correctly.
    remember: put your bean in package and call from package.

Maybe you are looking for

  • Account determination - exchange rate and valuation

    Hello All, we have a problem concerning our account determination for differences in exchange rate and valuation. When clearing open vendor items in foreign currency, a percentage of the difference goes to our exchange rate difference account (correc

  • Apple care contract for ipad

    does anyone know if an apple care contract bought in the uk would be valid in belgium? My mother (uk based) wants to buy an ipad for her grandchildren (living in Belgium).  She doesn't know if it makes sense to buy the apple care contract or not?  If

  • Risk terminator - Works in one system but not in the other

    Hi I have two SAP systems which is connected to one GRC system. Risk Terminator works well for the one system but does not work at all for the other. I have done the necessary configuration, set-up the RFC connector, tested the connectors, tested the

  • How to do an unattend install?

    Hello I have been tasked with created an auto build of Livecycle Workbench 9500 and ES 2 I think it is. I have seen posts saying I will email instructions but surely they should be freeely available, but I cannot find anyway of doing a reletively sim

  • Problem with lightbox gallery widget!

    Hi I'm using the lightbox gallery in conjuction with the css only menu and the psry content slideshow. I simply cannot get the lightbox to work, it opens up the images in a new page. www.studio-88.co.za Please help anyone!