MLUG: Re: [MLUG] Rant. (also comments on Off-topic)
Re: [MLUG] Rant. (also comments on Off-topic)
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Couple of notes - sorry, I'm probably the one who started the latest OT
stuff.  I'll try and remember EMAIL:PROTECTED - just hard
sometimes.
Second:
Java does let you use lousy code, like any other language.  However,
it's a bit different in Java and in this example.
Here's what I mean:

class DatabaseHandler {
  String s2 = null;
  String s3 = null;
  String s1 = "insert into mytable values (" + s1 + "," + s2 + ")";

//Now, the access rights on these variables are local the class.  You
can explicitly change their 
//access rights, with public, private, and protected as the options.
Private is NOT the default.
//protected means any object in the package can access the variable (I
think this is right - been 
//     a while since I've looked it up)
//private - INTERNAL only.  Nothing else can use it.  subclasses
however, can override these vals
//public - global variable, accessible to other classes
//With no specification, it's like a mixed access right setting. 
//so, in this case, s1, s2, s3 are all available to the methods inside
of the class

public void insertValues(String var1, String var2) {
s1 = var1;
s2 = var2;
//the above won't work, due to when the determination of s1 is made.  s1
upon creation
//was determined and fixed.  changing values used to create s1 won't
change s1
//instead, you'd normally do something a little different.  Typically, a
PreparedStatement
//would be used in Java, and setString(1, val1);  - the other way is a
wrapper class that
//emulates the string object.  The wrapper class would still need to be
able to
//handle a setString(1, var1) setting though, to handle this.

//the following will work properly.  you could also replace var1 and
var2.  However, this doesn't
//handle changes to s1 and s2 for later inserts.  You'd still have to
rebuild the string object
s1 = "insert into mytable values (" + var1 + "," + var2 + ")";

}

As a last note, if anyone wants a detailed explanation of how java and
jdbc works, please let me know.  I'd be more than willing to explain the
stuff.  Plus, explanations of the difference between JDBC 1.0, and JDBC
2.0 and getting software written in this to work under linux or windows,
plus why you should or shouldn't use a thin client vs. thick client for
jdbc drivers, etc.
Cheers!
Jason

-----Original Message-----
From: Kmicic
To: EMAIL:PROTECTED
Sent: 3/29/02 7:37 PM
Subject: Re: [MLUG] Rant.

yoda wrote:
> 
> I also am not fluent in how-you-say 'javanese'
> 
> On Fri, 29 Mar 2002, Mike Miller wrote:
> 
> > On Fri, 29 Mar 2002, McIntosh, Jason W. (UMC-Student) wrote:
> >
> > > Ok - everyone here I'll assume understands this.
> >
> > I don't think so!  I don't speak javanese, but maybe I'm the only
one.

the reason you guys may be having such a hard time with it is that on
top of being incorrect it's ridiculously bad code. I was not aware in
java you could make something so simple to be this convoluted - I
thought this level of magic was reserved for perl. It took me good few
minutes staring at it to see how ridiculous that is. I don't want to
spoil it for you, but once the realization hits you, you'll be awed.
Solution below... 

> String var = null;
> String var2 = null;
> 
> String insertString = "insert into mytable (field_1, field_2) 
> values (" + var + ", " + var2 + ")";
> 
> public void insertValues(String s1, String s2) {
>   var = s1;
>   var2 = s2;
>  //conn is an java.sql.Connection object
>   Statement s = conn.createStatement();
>   s.executeUpdate(insertString);
>  conn.commit();
> }
















keep scrolling, wouldn't want to give it away too soon for people with
large screens































Ok, in java you can declare variables on the fly. So he's creating a
string variable which will be his SQL command that he'll send. That
variable is created before the knowledge of what is actually to be
updated is available to the program. The function declared below has
that knowledge in the form of parameters passed to it, s1 and s2. So he
makes an assignment to global outer variables v1 and v2, which have been
used to create that damn update command string. But the string itself
remains unchanged, because numbers and strings in java are not assigned
by reference, but by value...so once the update SQL string has been
created its value does not change except for an explicit assignment.
This code would've actually worked fine if variables and strings were
objects (which would make for some insane programming). On a side note,
I thought java's philosophy was to eliminate bad programming. Why the
hell does it allow references to variables outside the function block
which have not been declared global?


Paul























> >
> > Mike
> >
> > --
> > To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
> >
> > Archives are available at http://mlug.missouri.edu/list-archives/
> >
> 
> --
> To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
> 
> Archives are available at http://mlug.missouri.edu/list-archives/
--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/
--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/