sql error: data types

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cypriot
    New Member
    • Sep 2007
    • 9

    sql error: data types

    Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types.

    This is my code.
    [code]

    savebutton.addA ctionListener( new ActionListener( )
    {
    public void actionPerformed (ActionEvent e)
    {
    try{

    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;

    con= DriverManager.g etConnection(ur l);

    String sqlStatement = "INSERT INTO PatientDB(Patie ntID,Name,Surna me,Phoneno,Date ofbirth,Complai nt) values(numberin put.getInteger( ),nameinput.get Text( ),surnameinput. getText(),phone input.getIntege r(),d ateofbirthinput .getInteger(),t ext.getText())" ;
    PreparedStateme nt pstmt = con.prepareStat ement(sqlStatem ent);
    pstmt.executeUp date();


    con.close();


    }

    catch(ClassNotF oundException ex)
    {}


    catch(SQLExcept ion ex)
    {
    ex.printStackTr ace();
    }

    }
    });
    [\code]





    [error]

    Hi. I want to insert data to ms access but I think I have a prob with data types.

    This is my code.
    [code]

    savebutton.addA ctionListener( new ActionListener( )
    {
    public void actionPerformed (ActionEvent e)
    {
    try{

    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;

    con= DriverManager.g etConnection(ur l);

    String sqlStatement = "insert into PatientDB(Patie ntID,Name,Surna me,Phoneno,Date ofbir th,Complaint) values(numberin put.getInteger( ),nameinput.get Text( ),surnameinput. getText(),phone input.getIntege r(),d ateofbirthinput .getInteger(),t et.getText())";
    PreparedStateme nt pstmt = con.prepareStat ement(sqlStatem ent);
    pstmt.executeUp date();


    con.close();


    }

    catch(ClassNotF oundException ex)
    {}


    catch(SQLExcept ion ex)
    {
    ex.printStackTr ace();
    }

    }
    });
    [\code]





    [error]

    java.sql.SQLExc eption: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'numberinput.ge tText' in expression.
    [\error]
    [\error]
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #2
    Originally posted by cypriot
    Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types.

    This is my code.
    [code]

    savebutton.addA ctionListener( new ActionListener( )
    {
    public void actionPerformed (ActionEvent e)
    {
    try{

    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;

    con= DriverManager.g etConnection(ur l);

    String sqlStatement = "INSERT INTO PatientDB(Patie ntID,Name,Surna me,Phoneno,Date ofbirth,Complai nt) values(numberin put.getInteger( ),nameinput.get Text( ),surnameinput. getText(),phone input.getIntege r(),d ateofbirthinput .getInteger(),t ext.getText())" ;
    PreparedStateme nt pstmt = con.prepareStat ement(sqlStatem ent);
    pstmt.executeUp date();


    con.close();


    }

    catch(ClassNotF oundException ex)
    {}


    catch(SQLExcept ion ex)
    {
    ex.printStackTr ace();
    }

    }
    });
    [\code]





    [error]

    Hi. I want to insert data to ms access but I think I have a prob with data types.

    This is my code.
    [code]

    savebutton.addA ctionListener( new ActionListener( )
    {
    public void actionPerformed (ActionEvent e)
    {
    try{

    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;

    con= DriverManager.g etConnection(ur l);

    String sqlStatement = "insert into PatientDB(Patie ntID,Name,Surna me,Phoneno,Date ofbir th,Complaint) values(numberin put.getInteger( ),nameinput.get Text( ),surnameinput. getText(),phone input.getIntege r(),d ateofbirthinput .getInteger(),t et.getText())";
    PreparedStateme nt pstmt = con.prepareStat ement(sqlStatem ent);
    pstmt.executeUp date();


    con.close();


    }

    catch(ClassNotF oundException ex)
    {}


    catch(SQLExcept ion ex)
    {
    ex.printStackTr ace();
    }

    }
    });
    [\code]





    [error]

    java.sql.SQLExc eption: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'numberinput.ge tText' in expression.
    [\error]
    [\error]
    Hi,
    Please use code tags while posting code. It makes it readable for other people.
    Check your query. They way you are calling functions to get values inside query is wrong.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Use Code Tags.
      I think your Query string will be like this.

      [code=java]

      String sqlStatement = "insert into PatientDB(Patie ntID,Name,Surna me,Phoneno,Date ofbir th,Complaint) values("+number input.getIntege r()+",'"+namein put.getText( )+"','"+surname input.getText() +"',"+phoneinpu t.getInteger()+ ","+d ateofbirthinput .getInteger()+" ,'"+tet.getText ()+"')";
      [/code]
      It will be something like this.

      Good Luck.

      Kind regards,
      Dmjpro.

      Comment

      • cypriot
        New Member
        • Sep 2007
        • 9

        #4
        Originally posted by madhoriya22
        Hi,
        Please use code tags while posting code. It makes it readable for other people.
        Check your query. They way you are calling functions to get values inside query is wrong.


        I couldnt figure out what is wrong.Please can you write.


        Code:
        String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(numberinput.getInteger(),nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by cypriot
          I couldnt figure out what is wrong.Please can you write.


          Code:
          String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(numberinput.getInteger(),nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";

          What is this?
          [code=java]
          numberinput.get Integer()
          [/code]
          Please explain me this!
          What is numberinput and getInteger?
          Please let me know!

          Kind regards,
          Dmjpro.

          Comment

          • cypriot
            New Member
            • Sep 2007
            • 9

            #6
            Originally posted by dmjpro
            What is this?
            [code=java]
            numberinput.get Integer()
            [/code]
            Please explain me this!
            What is numberinput and getInteger?
            Please let me know!

            Kind regards,
            Dmjpro.

            I have an application form with five textfields.

            I use numberinput: variable name for textfield for PatientID( PRİMARY KEY)
            nameinput : Name(Text)
            surnameinput: Surname(Text)
            phonenoinput Phone(Number)
            Complaint for textpane Complaint( Memo)



            I

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by cypriot
              I have an application form with five textfields.

              I use numberinput: variable name for textfield for PatientID( PRİMARY KEY)
              nameinput : Name(Text)
              surnameinput: Surname(Text)
              phonenoinput Phone(Number)
              Complaint for textpane Complaint( Memo)



              I
              So numberinput is your Java variable and getInteger is of it's Member method to retrieve the Integer Number the user inputs.
              Right?
              I assumed that I posted a solution look above.
              And try this and let me know what happens!
              :)

              Kind regards,
              Dmjpro.

              Comment

              • cypriot
                New Member
                • Sep 2007
                • 9

                #8
                Originally posted by dmjpro
                So numberinput is your Java variable and getInteger is of it's Member method to retrieve the Integer Number the user inputs.
                Right?
                I assumed that I posted a solution look above.
                And try this and let me know what happens!
                :)

                Kind regards,
                Dmjpro.

                I already use [code] numberinput.get Integer [\code]


                What I dont understand is why I get this error.


                [error]Undefined function 'numberinput.ge tText' in expression. [/error]

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by cypriot
                  I already use
                  Code:
                   numberinput.getInteger [\code]
                  
                  
                  What I dont understand is why I get this error.
                  
                  
                  [error]Undefined function 'numberinput.getText' in expression.  [/error]
                  Code:
                  Hello!
                  Try this one then let me know whether it errors or not!
                  :)
                  
                  [code=java]
                  String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir   th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
                  And read the Posting Guidelines while you do Post.
                  Good Luck with your Try. :)

                  Kind regards,
                  Dmjpro.

                  Comment

                  • cypriot
                    New Member
                    • Sep 2007
                    • 9

                    #10
                    Originally posted by dmjpro
                    Hello!
                    Try this one then let me know whether it errors or not!
                    :)

                    [code=java]
                    String sqlStatement = "insert into PatientDB(Patie ntID,Name,Surna me,Phoneno,Date ofbir th,Complaint) values("+number input.getIntege r()+",'"+namein put.getText( )+"','"+surname input.getText() +"',"+phoneinpu t.getInteger()+ ","+d ateofbirthinput .getInteger()+" ,'"+tet.getText ()+"')";
                    [/code]

                    And read the Posting Guidelines while you do Post.
                    Good Luck with your Try. :)

                    Kind regards,
                    Dmjpro.

                    I tried it before but it didnt work. I think it is used with Statement. Here I use PreparedStateme nt so quotes are not needed.
                    And please can you tell me ( ",' ") what are these quotes used for?

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Originally posted by cypriot
                      I tried it before but it didnt work. I think it is used with Statement. Here I use PreparedStateme nt so quotes are not needed.
                      And please can you tell me ( ",' ") what are these quotes used for?
                      What it says when you use my Query String?
                      And try with simple Statement interface.
                      Good Luck.

                      Kind regards,
                      Dmjpro.

                      Comment

                      • cypriot
                        New Member
                        • Sep 2007
                        • 9

                        #12
                        Originally posted by dmjpro
                        What it says when you use my Query String?
                        And try with simple Statement interface.
                        Good Luck.

                        Kind regards,
                        Dmjpro.

                        Using quotes creates more confusion. I had compilation errors.
                        So I took a different approach. ı used conversion methods.

                        I want to convert PatientID and phone fields ( numberinput and phoneinput).

                        So I used the method below.


                        Code:
                        public void AddPatient()
                                 {
                                   [B] int i=Integer.parseInt(numberinput.getText()); [/B]
                                     
                                                  try{
                        	             
                        	     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        	     
                        	       con= DriverManager.getConnection(url);
                        	     
                        String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(i,nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";
                        PreparedStatement pstmt = con.prepareStatement(sqlStatement);
                                    
                        
                        
                        	       con.close();
                        	       
                        	       
                                 }
                        
                              catch(ClassNotFoundException e)
                                       {}
                        	 
                                    
                                catch(SQLException ex)
                                {
                                ex.printStackTrace();
                                }
                        
                            }  
                        }

                        Then I got this error.

                        [ERROR]

                        va.lang.NumberF ormatException: For input string: ""
                        at java.lang.Numbe rFormatExceptio n.forInputStrin g(NumberFormatE xception.java:4 8)
                        [/ERROR]

                        Comment

                        • dmjpro
                          Top Contributor
                          • Jan 2007
                          • 2476

                          #13
                          Look!

                          suppose you have a five variables.
                          [code=java]
                          int a,b,c;
                          String d,e;
                          String str_qty = "insert into table_name(AA,B B,CC,DD,EE) values("+a+","+ b+","+c+",'"+d+ "',"+e+"')" ;
                          //Now check this code again.
                          //In SQL or Oracle the String should be separated with '' and numbers are not.
                          [/code]

                          And your NumberFormatExc eption comes because of invalid String.
                          As for example 123g this String can't be parsed as Integer.
                          And here is your Empty String, that's why such Error comes up.

                          Kind regards,
                          Dmjpro.

                          Comment

                          • cypriot
                            New Member
                            • Sep 2007
                            • 9

                            #14
                            Originally posted by dmjpro
                            Look!

                            suppose you have a five variables.
                            [code=java]
                            int a,b,c;
                            String d,e;
                            String str_qty = "insert into table_name(AA,B B,CC,DD,EE) values("+a+","+ b+","+c+",'"+d+ "',"+e+"')" ;
                            //Now check this code again.
                            //In SQL or Oracle the String should be separated with '' and numbers are not.
                            [/code]

                            And your NumberFormatExc eption comes because of invalid String.
                            As for example 123g this String can't be parsed as Integer.
                            And here is your Empty String, that's why such Error comes up.

                            Kind regards,
                            Dmjpro.

                            I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getT ext' and now I get insert syntax error.
                            Code:
                            public void AddPatient()
                                     {
                            
                                         
                                         
                                        try{
                            	             
                            	     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                            	     
                            	       con= DriverManager.getConnection(url);
                            	     
                            String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
                                  st= con.createStatement();
                                        
                                    st.execute(sqlStatement);
                            
                            	       con.close();

                            Comment

                            • madhoriya22
                              Contributor
                              • Jul 2007
                              • 251

                              #15
                              Originally posted by cypriot
                              I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getT ext' and now I get insert syntax error.
                              Code:
                               
                              public void AddPatient()
                              {
                               
                               
                               
                              try{
                               
                              	 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                               
                              	 con= DriverManager.getConnection(url);
                               
                              String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
                              st= con.createStatement();
                               
                              st.execute(sqlStatement);
                               
                              	 con.close();
                              Hi,
                              I will again suggest you to check your query. It is wrong. Check the quotes(') you have put in the query. they are not matching.

                              Comment

                              Working...