Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Can't use a var...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 1939 of 1998
Post > Topic >>

Can't use a variable for a column name?

by cmattmiller@[EMAIL PROTECTED] (Chris) Apr 24, 2008 at 12:25 PM

------=_Part_19761_1619648.1209057916539
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

A user enters a name into a textfield and clicks on a "Find" button.
Depending on which text field the user entered the data, the appropriate
column name in the table is used for fieldName and the entered text is
passName.  However, the fieldName doesn't return anything.  But if I
replace
fieldName with the column name ("WHERE first_name='"), the program returns
values.  Can't we use variables for column names or do I have to just put
it
all in an if/else statement?

Here is my code:

              result = fe.executeQuery("SELECT first_name, last_name,
emp_nbr, emp_type_code, emp_status_code, emp_work_center " +
                                            "FROM employee " +
                                            "WHERE
'"+fieldName+"'='"+passName+"'");

------=_Part_19761_1619648.1209057916539
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

A user enters a name into a textfield and clicks on a &quot;Find&quot;
button.&nbsp; Depending on which text field the user entered the data, the
appropriate column name in the table is used for fieldName and the entered
text is passName.&nbsp; However, the fieldName doesn&#39;t return
anything.&nbsp; But if I replace fieldName with the column name
(&quot;WHERE first_name=&#39;&quot;), the program returns values.&nbsp;
Can&#39;t we use variables for column names or do I have to just put it
all in an if/else statement?<br>
<br>Here is my
code:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
result = fe.executeQuery(&quot;SELECT first_name, last_name, emp_nbr,
emp_type_code, emp_status_code, emp_work_center &quot;
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&quot;FROM employee &quot; +<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&quot;WHERE
&#39;&quot;+fieldName+&quot;&#39;=&#39;&quot;+passName+&quot;&#39;&quot;);<br>

------=_Part_19761_1619648.1209057916539--
 




 3 Posts in Topic:
Can't use a variable for a column name?
cmattmiller@[EMAIL PROTEC  2008-04-24 12:25:16 
Re: Can't use a variable for a column name?
laurenz.albe@[EMAIL PROTE  2008-04-25 08:39:54 
Re: Can't use a variable for a column name?
cmattmiller@[EMAIL PROTEC  2008-04-25 12:58:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Thu Jul 24 13:14:36 CDT 2008.