9 Replies Latest reply: May 21, 2008 1:07 AM by 807601 RSS

    int problem in sql

    807601
      hello,

      i am using a sql insert to a database. sql like this,

      insert into table(a,b,c) values("+ value1 +",'"+ value2 +"','"+ value3 +"')

      value1 is an int type so getting an error. how can i fix this?
        • 1. Re: int problem in sql
          807601
          and that error message is? We don't read minds. Why do you have quotes around the variable names?
          • 2. Re: int problem in sql
            807601
            ridvanbi wrote:
            hello,

            i am using a sql insert to a database. sql like this,

            insert into table(a,b,c) values("+ value1 +",'"+ value2 +"','"+ value3 +"')

            value1 is an int type so getting an error. how can i fix this?
            what kind of error / exception you are getting? paste the stackTrace here.

            and expalain me about the query. what is "table" here? is that the table name? and what about value1? is that a int variable or else a string variable which holds a number as it's value?


            Diablo
            • 3. Re: int problem in sql
              807601
              flounder wrote:
              and that error message is? We don't read minds. Why do you have quotes around the variable names?
              because he pasted it from his java source code.
              • 4. Re: int problem in sql
                807601
                this is the error

                The operator + cannot be applied to ""Insert into TABLE(a,b,c) Values("" and "value1"; type string is incompatible with nillable:int
                • 5. Re: int problem in sql
                  807601
                  Ah, so the quotes are not around the variables but around everything else. Then it looks like a concatenation problem. Better yet use a PreparedStatement.
                  • 6. Re: int problem in sql
                    807601
                    ridvanbi wrote:
                    this is the error

                    The operator + cannot be applied to ""Insert into TABLE(a,b,c) Values("" and "value1"; type string is incompatible with nillable:int
                    I guess he pasted this from his java code where his query is like this. but while pasting here he didn't enclose it with code tags so some + signs got missed. actual query is like this.
                    insert into table(a,b,c) values("+value1+",'"+value2+"','"+value3+"')
                    Diablo
                    • 7. Re: int problem in sql
                      807601
                      Try to rework the concatenation in your query to be more like this:
                      String query = "insert into table(a,b,c) values('"+value1+"','"+value2+"','"+value3+"')";
                      And place
                       tags around any code, even a short query that you place on the forum.  It really helps the readability.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      • 8. Re: int problem in sql
                        807601
                        Code_Master_S-Funk wrote:
                        Try to rework the concatenation in your query to be more like this:
                        String query = "insert into table(a,b,c) values('"+value1+"','"+value2+"','"+value3+"')";
                        And place
                         tags around any code, even a short query that you place on the forum.  It really helps the readability.
                        wait a second. he said that the first field is Integer. then why you are keeping that in single quotes(' '). ?
                        • 9. Re: int problem in sql
                          807601
                          ridvanbi wrote:
                          this is the error

                          The operator + cannot be applied to ""Insert into TABLE(a,b,c) Values("" and "value1"; type string is incompatible with nillable:int
                          Do one thing, place your entire code. or else paste atleast the code snippet where you've written this query.