Java and SQL


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Java and SQL

  1. #1
    Jaap Guest

    Java and SQL


    Hello,
    I have a little question.
    I have written some code, but it doesn't seem to work. I have no idea why.
    In java I've created a couple of parameters.
    ...
    String Tabel = (String) userSession.getValue("Tabel");
    String Param1 = (String) userSession.getValue("Param1");
    String Param2 = (String) userSession.getValue("Param2")
    ....
    With a form you can fill in the params.
    Then I wanted to make a query like this :
    ResultSet rs = stmt.executeQuery("SELECT Param1, Param2 FROM Tabel");
    ....
    But it doesn't seem to work.

    When I use this, it works. I think has to do with the parameters wich I can't
    use in the sql query.
    ...
    ResultSet rs = stmt.executeQuery("SELECT ID, NAAM FROM BVZB_BEHE.BVUW_KENGETALLEN");
    ...
    Please can somebody help me ?



  2. #2
    Paul Clapham Guest

    Re: Java and SQL

    ResultSet rs = stmt.executeQuery("SELECT " + Param1 + ", " + Param2 + " FROM
    " + Tabel);

    PC2

    "Jaap" <jfmeems@hotmail.com> wrote in message
    news:3c3edb05$1@147.208.176.211...
    >
    > Hello,
    > I have a little question.
    > I have written some code, but it doesn't seem to work. I have no idea why.
    > In java I've created a couple of parameters.
    > ..
    > String Tabel = (String) userSession.getValue("Tabel");
    > String Param1 = (String) userSession.getValue("Param1");
    > String Param2 = (String) userSession.getValue("Param2")
    > ...
    > With a form you can fill in the params.
    > Then I wanted to make a query like this :
    > ResultSet rs = stmt.executeQuery("SELECT Param1, Param2 FROM Tabel");
    > ...
    > But it doesn't seem to work.
    >
    > When I use this, it works. I think has to do with the parameters wich I

    can't
    > use in the sql query.
    > ..
    > ResultSet rs = stmt.executeQuery("SELECT ID, NAAM FROM

    BVZB_BEHE.BVUW_KENGETALLEN");
    > ..
    > Please can somebody help me ?
    >
    >




  3. #3
    Chuck Nelson Guest

    Re: Java and SQL


    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >ResultSet rs = stmt.executeQuery("SELECT " + Param1 + ", " + Param2 + "

    FROM
    >" + Tabel);
    >
    >PC2
    >
    >"Jaap" <jfmeems@hotmail.com> wrote in message
    >news:3c3edb05$1@147.208.176.211...
    >>
    >> Hello,
    >> I have a little question.
    >> I have written some code, but it doesn't seem to work. I have no idea

    why.
    >> In java I've created a couple of parameters.
    >> ..
    >> String Tabel = (String) userSession.getValue("Tabel");
    >> String Param1 = (String) userSession.getValue("Param1");
    >> String Param2 = (String) userSession.getValue("Param2")
    >> ...
    >> With a form you can fill in the params.
    >> Then I wanted to make a query like this :
    >> ResultSet rs = stmt.executeQuery("SELECT Param1, Param2 FROM Tabel");
    >> ...
    >> But it doesn't seem to work.
    >>
    >> When I use this, it works. I think has to do with the parameters wich

    I
    >can't
    >> use in the sql query.
    >> ..
    >> ResultSet rs = stmt.executeQuery("SELECT ID, NAAM FROM

    >BVZB_BEHE.BVUW_KENGETALLEN");
    >> ..
    >> Please can somebody help me ?
    >>
    >>

    >
    >


    Paul, You need to construct your SQL statement from the parameters (which
    are strings). Try something like this:

    stmt.executeQuery("SELECT " + Param1 + ", " + Param2 + " FROM " + Tabel);

    Have fun.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center