DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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.


Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links