Results 1 to 4 of 4
  1. #1
    herfnai is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Default SELECT FROM WHERE query

    i have java access sql server

    String tablename=jtextfield1.getText();
    String variablename=jtextfield2.getText();

    "SELECT * FROM " + tablename + " WHERE " + tablename.fieldname + " = " + variablename;

    error invalid column variablename

  2. #2
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    u cannot user clumn name like a variable

  3. #3
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    "SELECT * FROM " + tablename + " WHERE " +" blank space "+ tablename.fieldname + " = " + variablename;



    try providing space in after where .... it should work
    DevZ;)

  4. #4
    wolve634's Avatar
    wolve634 is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Smile

    You have declared your tablename as String , but are using as object ! this may be one of the reason your code fails! or if your table name is not dynamic enclose it with double quotes ! if your table.fieldname is of String type then the result of variablename must be in quotes , namely:

    "where table.fieldname= '"+variablename+"'";

    :)

Similar Threads

  1. problem in select query
    By herfnai in forum JDBC
    Replies: 0
    Last Post: 08-17-2008, 12:47 PM
  2. Select Count
    By Apple2 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-29-2008, 10:02 AM
  3. Using a variable in a SELECT FROM WHERE query
    By cplmckenzie in forum JDBC
    Replies: 12
    Last Post: 04-23-2008, 04:24 AM
  4. JDBC select problem
    By abhiN in forum JDBC
    Replies: 0
    Last Post: 03-12-2008, 09:09 AM
  5. Select specific cell
    By Echilon in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •