hey... hi there .. i m currently using NetBeans for creating A simple desktop application in java,,,, so in the registration page.. i m getting some errors

my code is

import java.sql.*;
import java.lang.*;
       /*
 * register1.java
 *
 * Created on September 7, 2010, 10:59 AM
 */



/**
 *
 * @author  ASPHire
 */
public class register1 extends javax.swing.JFrame {
    private Object request;
    private Object st;

    /** Creates new form register1 */
    public register1() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("REGISTERATION ");

        jLabel2.setText("NAME");

        jLabel3.setText("MAIL ID");

        jLabel4.setText("COUNTRY");

        jLabel5.setText("COMPANY");

        jButton1.setText("SUBMIT");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("RESET");

        jTextField1.setName("NAME"); // NOI18N

        jTextField2.setName("MAIL_ID"); // NOI18N

        jTextField3.setName("COUNTRY"); // NOI18N

        jTextField4.setName("COMPANY"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                                .addComponent(jLabel1)
                                .addGap(179, 179, 179))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(58, 58, 58)
                                .addComponent(jButton2)
                                .addContainerGap())))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                        .addContainerGap(179, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(122, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
   try
        {
        String NAME=request.getParameter("NAME"); 
     String MAIL_ID=request.getParameter("MAIL_ID");
     String COUNTRY=request.getParameter("COUNTRY");
     String COMPANY=request.getParameter("COMPANY");

                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

        Connection con=DriverManager.getConnection("Jdbc:Odbc:Hotel");

    //  Statement st=con.createStatement();
        PreparedStatement st=con.prepareStatement("insert into REG1(NAME,MAIL_ID,COUNTRY,COMPANY) values(?,?,?,?)");

        st.setString(1,NAME);
        st.setString(2,MAIL_ID);
        st.setString(3,COUNTRY);
        st.setString(4,COMPANY);
  st.executeUpdate();  } 
   catch(Exception e)
        {

            System.out.println(e);
        }
             ;// TODO add your handling code here:
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new register1().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration

}

and HOW COULD i create a dsn NAME as in normal ar there is some special case for NETBEANS

Recommended Answers

All 19 Replies

see this snap shot....

can you post the above code in the

tags please. Its easier to see

ok...

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   try
        {
      String NAME= request.getParameter("NAME"); // got error here
     String MAIL_ID= request.getParameter("MAIL_ID");// got error here
     String COUNTRY= request.getParameter("COUNTRY");// got error here
    String COMPANY= request.getParameter("COMPANY");// got error here

                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

        Connection con=DriverManager.getConnection("Jdbc:Odbc:Hotel");

    //  Statement st=con.createStatement();
        PreparedStatement st=con.prepareStatement("insert into REG1(NAME,MAIL_ID,COUNTRY,COMPANY) values(?,?,?,?)");

        st.setString(1,NAME);
        st.setString(2,MAIL_ID);
        st.setString(3,COUNTRY);
        st.setString(4,COMPANY);
  st.executeUpdate();  } 
   catch(Exception e)
        {

            System.out.println(e);
        }
             ;// TODO add your handling code here:
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new register1().setVisible(true);
            }
        });

It may be because you are trying to assign an object to a String, instead of assigning that String to the object. what happens if you had

String NAME;
 request.getParameter("NAME") = NAME;

Don't even know if that makes sense my friend! :)

also not working

Same error?

Member Avatar for coil

It may be because you are trying to assign an object to a String, instead of assigning that String to the object. what happens if you had

String NAME;
 request.getParameter("NAME") = NAME;

Don't even know if that makes sense my friend! :)

No, the original syntax was correct. String name=request.getParameter("NAME") should work given the following:
1. "request" is a valid variable.
2. The class that "request" is an instance of has a getParameter method which a) takes a String argument and b) returns a String.

Check that you've satisfied the above.

No, the original syntax was correct. String name=request.getParameter("NAME") should work given the following:
1. "request" is a valid variable.
2. The class that "request" is an instance of has a getParameter method which a) takes a String argument and b) returns a String.

Check that you've satisfied the above.

Do you know any examples of what I said where I would be correct? Any scenarios you can think of off your head? I remember a teacher telling me i needed to switch the expressions on each side to fix a problem I had before.

C:\Documents and Settings\ASPHire\My Documents\NetBeansProjects\schedular\src\register1.java:147: cannot find symbol
symbol : variable request
location: class register1
String COMPANY= request.getParameter("COMPANY");
i got that in netbeans output console

C:\Documents and Settings\ASPHire\My Documents\NetBeansProjects\schedular\src\register1.java:147: cannot find symbol
symbol : variable request
location: class register1
String COMPANY= request.getParameter("COMPANY");
i got that in netbeans output console

C:\Documents and Settings\ASPHire\My Documents\NetBeansProjects\schedular\src\register1.java:147: cannot find symbol
symbol : variable request
location: class register1
String COMPANY= request.getParameter("COMPANY");
i got that in netbeans output console

I have never seen this Object class being used before but

//you have
private Object request;
//If it is like creating an instance any other object I would write it as:
private Object request = new Object();

Maybe this is why it cannot find request, because it wasn't initialized?

Member Avatar for coil

It may be because you are trying to assign an object to a String, instead of assigning that String to the object.

Not sure quite what you're asking, but I would assume you're posting stuff that you think will resolve the problem, and is therefore correct...

As to switching the sides, that may sometimes work, but it's not very good practice to just randomly switch sides or add code segments. You should understand why something works or not.

In this specific case, the variable on the left is assigned a value. The OP was getting a value from a method, therefore it follows that the returned value should be assigned to a variable. It wouldn't make sense to assign a method a String.

acctually i m creating desktop application so i m asking that "request .get parameter" is worked here or not because thats used in JSP programming.

As akill10 mentioned above, you have not initialized the request variable. You have only declared it.

so how could i initilize...

You don't actually. 'request' doesn't really apply in your desktop application. You need to get the text from your text fields.

like it.... 1st text field is name of "T1" so i just have to put...
String MAME= T1.getText();

Member Avatar for coil

Yes, that should work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.