From: francan00 on
I am trying to translate the PHP script into Java.

PHP:

if(isset($_GET['getClientId'])){
$res = mysql_query("select * from tableOne where clientID='".
$_GET['getClientId']."'") or die(mysql_error());
if($inf = mysql_fetch_array($res)

....


My attempt in Java and it is giving me errors with getClientId part
and lost in fetching array part. Please advise any corrections I
need?
Java:
//db connection part here...

try {
String res = "";
if(getParameter("getClientId")) {
res = stmt.executeQuery("select * from tableOne where clientID='" +
getParameter("getClientId") + "');

String $inf [];
if($inf.equals(getParameterValues($res)) {

.....
From: RedGrittyBrick on
francan00(a)yahoo.com wrote:
> I am trying to translate the PHP script into Java.
>
> [snip]
>
> My attempt in Java and it is giving me errors with getClientId part

I always cut and paste exact error messages into newsgroup postings -
otherwise you are hiding information vital to solving your problem. Why
make people guess what the error message might be?

> and lost in fetching array part. Please advise any corrections I
> need?
> Java:
> //db connection part here...
>
> try {
> String res = "";
> if(getParameter("getClientId")) {

Presumably this is within
public class SomeServlet extends HttpServlet {


> res = stmt.executeQuery("select * from tableOne where clientID='" +
> getParameter("getClientId") + "');
>
> String $inf [];

Unless this is some variant of Java I am unfamiliar with, variable names
should not be prefixed with a dollar sign.

> if($inf.equals(getParameterValues($res)) {

and array elements should be indexed - e.g. if (inf[0].equals(...)) {


--
RGB
From: Andreas Leitgeb on
francan00(a)yahoo.com <francan00(a)yahoo.com> wrote:
> PHP:
> if(isset($_GET['getClientId'])){
> $res = mysql_query("select * from tableOne where clientID='".
> $_GET['getClientId']."'") or die(mysql_error());
> if($inf = mysql_fetch_array($res)

I wonder, where the value for 'getClientId' comes from.
If it is part of the browser request, then this is highly
susceptible to SQL-injection, and about equivalent to
posting your web-server's administrator password here.

If the value for 'getClientId' is a guaranteed integer,
and stays on the server (i.e. doesn't do a ping-pong
to the client), and only then, it is ok, and my warning
moot.

From: Lew on
francan00(a)yahoo.com wrote:
>> String $inf [];

RedGrittyBrick wrote:
> Unless this is some variant of Java I am unfamiliar with, variable names
> should not be prefixed with a dollar sign.

They should not be, but it's legal, strictly speaking.

<http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8>
> The Java letters include uppercase and lowercase ASCII Latin letters
> A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons,
> the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024).
> The $ character should be used only in mechanically generated source code
> or, rarely, to access preexisting names on legacy systems.

Nevertheless, francan00, you should follow RGB's advice and eschew dollar
signs in your Java identifiers. It may only say "should", but that's pretty
close to "must" in this case.

francan00(a)yahoo.com wrote:
>> if($inf.equals(getParameterValues($res)) {

RedGrittyBrick wrote:
> and array elements should be indexed - e.g. if (inf[0].equals(...)) {

The method name 'getParameterValues()' implies return of an array or
collection, so it is possible that the expression was meant to refer to the
array as a whole.

With such tiny, incomplete fragments of code from the OP, one can only
speculate, of course.

If that method does return an array, the OP may be surprised that 'equals()'
between arrays doesn't do what they expect.

--
Lew
From: Roedy Green on
On Sun, 29 Jun 2008 12:52:09 -0700 (PDT), francan00(a)yahoo.com wrote,
quoted or indirectly quoted someone who said :

> $inf

See http://mindprod.com/jgloss/codingconventions.html


Don't use $ in Java variable names.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com