Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > What's wrong with this code?

Reply
Thread Tools

What's wrong with this code?

 
 
Paul
Guest
Posts: n/a
 
      06-28-2004
Considering all aspects like style, naming conventions, logic etc...
Is this code OK? Please comment...

public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT OrderID, Customer FROM Orders";

SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);

myConnection.Open();

SqlDataReader myReader = myCommand.ExecuteReader();

while (myReader.Read())
{
Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
}

myReader.Close();
myConnection.Close();
}

Thanks,
Paul.
 
Reply With Quote
 
 
 
 
Liz
Guest
Posts: n/a
 
      06-28-2004

"Paul" <> wrote in message
news: om...
> Considering all aspects like style, naming conventions, logic etc...
> Is this code OK? Please comment...
>
> public void ReadMyData(string myConnString)
> {
> string mySelectQuery = "SELECT OrderID, Customer FROM Orders";
>
> SqlConnection myConnection = new SqlConnection(myConnString);
> SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
>
> myConnection.Open();
>
> SqlDataReader myReader = myCommand.ExecuteReader();
>
> while (myReader.Read())
> {
> Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
> }
>
> myReader.Close();
> myConnection.Close();
> }
>
> Thanks,
> Paul.


I cut and pasted your offering and ran a tool "jcsc" on it. This tool
is supposed to see if your code matches the Sun coding standards for java.
Here is the output. Note that the NCSS = lines of code = 0, so it thinks
what you have is not valid enough to count it.
---
C:\tmp>jcsc test1.java
Encountered "void" at line 1, column 8.
Was expecting one of:
"abstract" ...
"interface" ...
"public" ...
"strictfp" ...
"final" ...
"class" ...

File: test1.java

Violations:

test1.java:1:1:interface Declaration JavaDoc does not provide the required
'@author' tag:TypeDeclarationAuthor:3
test1.java:1:1:interface Declaration JavaDoc does not provide the required
'@version' tag:TypeDeclarationVersion:3

2 violation(s) found

Metrics:


Total NCSS count : 0
Total Methods count : 0


 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      06-28-2004
Paul wrote:
> Considering all aspects like style, naming conventions, logic etc...
> Is this code OK? Please comment...

<snip>

How are we to know? There are methods you haven't included so we
don't know their signatures, specifically what exceptions can be
thrown.
Variable names are copacetic although the method names shouldn't
have a leading capital letter. I prefer the K&R style of braces
but this has always been a contentious issue.
I'm not about to enter into a religious discussion on that topic...

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-28-2004
On 27 Jun 2004 20:03:14 -0700, (Paul) wrote or
quoted :

>public void ReadMyData(string myConnString)
>{
> string mySelectQuery = "SELECT OrderID, Customer FROM Orders";
>
> SqlConnection myConnection = new SqlConnection(myConnString);
> SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
>
> myConnection.Open();
>
> SqlDataReader myReader = myCommand.ExecuteReader();
>
> while (myReader.Read())
> {
> Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
> }
>
> myReader.Close();
>


You could have discovered some of the errors with JavaC or better
Jikes in pendant mode. See also http://mindprod.com/jgloss/lint.html

The things that stand out for me is the violation of the caps
conventions. See http://mindprod.com/jgloss/codingconventions.html

You are writing "string" for "String" which is not only a sylistic
error, but a syntax error as well.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-28-2004
On Mon, 28 Jun 2004 04:34:07 GMT, Roedy Green
<look-> wrote or quoted :

>You could have discovered some of the errors with JavaC or better
>Jikes in pendant mode.


rather "pedant" mode.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      06-28-2004
Paul wrote:

> Considering all aspects like style, naming conventions, logic etc...
> Is this code OK? Please comment...
>
> public void ReadMyData(string myConnString)
> {
> string mySelectQuery = "SELECT OrderID, Customer FROM Orders";
>
> SqlConnection myConnection = new SqlConnection(myConnString);
> SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
>
> myConnection.Open();
>
> SqlDataReader myReader = myCommand.ExecuteReader();
>
> while (myReader.Read())
> {
> Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
> }
>
> myReader.Close();
> myConnection.Close();
> }
>
> Thanks,
> Paul.


Why are you posting C# code on a Java newsgroup? They don't have the same
naming conventions anyway.

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57