Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Some other notes:

  1. Don't mix naming styles:

     String DataURL = "jdbc:db://localhost:5112/users";
     String loginName = "stackoverflow"
    

Variable names should be camelCase Variable names should be camelCase (with lowercase first letter).

  1. Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

     final boolean hasUser = result.next();
     if (hasUser) {
     iUserID = result.getInt(1);
     loginUser = result.getString(2);
     } else {
     wr.println ("you cannot login in !Access Denied!");
     }
    

Or even better:

 final boolean hasUser = result.next();
 if (!hasUser) {
 wr.println ("you cannot login in !Access Denied!");
 return; // etc.
 }
 final int userID = result.getInt(1);
 final String loginUser = result.getString(2);

It removes magic strings from the code and makes it easier to read.

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

  1. Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

     userID = result.getInt("UserID");
     loginUser = result.getString("Username);
    

It also removes some magic numbers from the code and makes it easier to read.

  1. This:

     PrintWriter wr = response.getWriter ();
    

should be:

 PrintWriter wr = response.getWriter();

(From here):

Note that a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

  1. I'd use longer variable names for readability:

     PrintWriter writer = response.getWriter();
    

Some other notes:

  1. Don't mix naming styles:

     String DataURL = "jdbc:db://localhost:5112/users";
     String loginName = "stackoverflow"
    

Variable names should be camelCase (with lowercase first letter).

  1. Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

     final boolean hasUser = result.next();
     if (hasUser) {
     iUserID = result.getInt(1);
     loginUser = result.getString(2);
     } else {
     wr.println ("you cannot login in !Access Denied!");
     }
    

Or even better:

 final boolean hasUser = result.next();
 if (!hasUser) {
 wr.println ("you cannot login in !Access Denied!");
 return; // etc.
 }
 final int userID = result.getInt(1);
 final String loginUser = result.getString(2);

It removes magic strings from the code and makes it easier to read.

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

  1. Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

     userID = result.getInt("UserID");
     loginUser = result.getString("Username);
    

It also removes some magic numbers from the code and makes it easier to read.

  1. This:

     PrintWriter wr = response.getWriter ();
    

should be:

 PrintWriter wr = response.getWriter();

(From here):

Note that a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

  1. I'd use longer variable names for readability:

     PrintWriter writer = response.getWriter();
    

Some other notes:

  1. Don't mix naming styles:

     String DataURL = "jdbc:db://localhost:5112/users";
     String loginName = "stackoverflow"
    

Variable names should be camelCase (with lowercase first letter).

  1. Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

     final boolean hasUser = result.next();
     if (hasUser) {
     iUserID = result.getInt(1);
     loginUser = result.getString(2);
     } else {
     wr.println ("you cannot login in !Access Denied!");
     }
    

Or even better:

 final boolean hasUser = result.next();
 if (!hasUser) {
 wr.println ("you cannot login in !Access Denied!");
 return; // etc.
 }
 final int userID = result.getInt(1);
 final String loginUser = result.getString(2);

It removes magic strings from the code and makes it easier to read.

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

  1. Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

     userID = result.getInt("UserID");
     loginUser = result.getString("Username);
    

It also removes some magic numbers from the code and makes it easier to read.

  1. This:

     PrintWriter wr = response.getWriter ();
    

should be:

 PrintWriter wr = response.getWriter();

(From here):

Note that a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

  1. I'd use longer variable names for readability:

     PrintWriter writer = response.getWriter();
    
added 131 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

1, Don't mix naming styles:

String DataURL = "jdbc:db://localhost:5112/users";
String loginName = "stackoverflow"
  1. Don't mix naming styles:

     String DataURL = "jdbc:db://localhost:5112/users";
     String loginName = "stackoverflow"
    

Variable names should be camelCaseVariable names should be camelCase (with lowercase first letter).http://stackoverflow.com/questions/2082729/to-camelcase-or-not-to-camel-case

  1. Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

     final boolean hasUser = result.next();
     if (hasUser) {
     iUserID = result.getInt(1);
     loginUser = result.getString(2);
     } else {
     wr.println ("you cannot login in !Access Denied!");
     }
    

2, Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flagOr even better:

final boolean hasUser = result.next();
if (hasUser) {
  iUserID =if result.getInt(1!hasUser); {
 loginUser = result.getString(2);
} else {
 wr.println ("you cannot login in !Access Denied!");
}

Or even better:

final boolean hasUser = result.next();
if (!hasUser) {
 return; // wretc.println ("you cannot login in !Access Denied!");}
 return; // etc.
}
final int userID = result.getInt(1);
final String loginUser = result.getString(2);

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

3, Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

userID = result.getInt("UserID");
loginUser = result.getString("Username);
  1. Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

     userID = result.getInt("UserID");
     loginUser = result.getString("Username);
    
  1. This:

     PrintWriter wr = response.getWriter ();
    

4,should be:

PrintWriter wr = response.getWriter ();

should be

PrintWriter wr = response.getWriter();

From(From http://www.oracle.com/technetwork/java/codeconventions-141388.html#475here ):

5, I'd use longer variable names:

PrintWriter writer = response.getWriter();

It's more readable.

  1. I'd use longer variable names for readability:

     PrintWriter writer = response.getWriter();
    

1, Don't mix naming styles:

String DataURL = "jdbc:db://localhost:5112/users";
String loginName = "stackoverflow"

Variable names should be camelCase (with lowercase first letter).http://stackoverflow.com/questions/2082729/to-camelcase-or-not-to-camel-case

2, Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

final boolean hasUser = result.next();
if (hasUser) {
  iUserID = result.getInt(1);
 loginUser = result.getString(2);
} else {
 wr.println ("you cannot login in !Access Denied!");
}

Or even better:

final boolean hasUser = result.next();
if (!hasUser) {
 wr.println ("you cannot login in !Access Denied!");
 return; // etc.
}
final int userID = result.getInt(1);
final String loginUser = result.getString(2);

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

3, Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

userID = result.getInt("UserID");
loginUser = result.getString("Username);

4,

PrintWriter wr = response.getWriter ();

should be

PrintWriter wr = response.getWriter();

From http://www.oracle.com/technetwork/java/codeconventions-141388.html#475

5, I'd use longer variable names:

PrintWriter writer = response.getWriter();

It's more readable.

  1. Don't mix naming styles:

     String DataURL = "jdbc:db://localhost:5112/users";
     String loginName = "stackoverflow"
    

Variable names should be camelCase (with lowercase first letter).

  1. Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

     final boolean hasUser = result.next();
     if (hasUser) {
     iUserID = result.getInt(1);
     loginUser = result.getString(2);
     } else {
     wr.println ("you cannot login in !Access Denied!");
     }
    

Or even better:

final boolean hasUser = result.next();
 if (!hasUser) {
 wr.println ("you cannot login in !Access Denied!");
 return; // etc. }
 final int userID = result.getInt(1);
final String loginUser = result.getString(2);

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

  1. Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

     userID = result.getInt("UserID");
     loginUser = result.getString("Username);
    
  1. This:

     PrintWriter wr = response.getWriter ();
    

should be:

 PrintWriter wr = response.getWriter();

(From here ):

  1. I'd use longer variable names for readability:

     PrintWriter writer = response.getWriter();
    
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157

Some other notes:

1, Don't mix naming styles:

String DataURL = "jdbc:db://localhost:5112/users";
String loginName = "stackoverflow"

Variable names should be camelCase (with lowercase first letter). http://stackoverflow.com/questions/2082729/to-camelcase-or-not-to-camel-case

2, Instead of checking that iUserID is -1 or not check the result of result.next() and set a boolean flag:

final boolean hasUser = result.next();
if (hasUser) {
 iUserID = result.getInt(1);
 loginUser = result.getString(2);
} else {
 wr.println ("you cannot login in !Access Denied!");
}

Or even better:

final boolean hasUser = result.next();
if (!hasUser) {
 wr.println ("you cannot login in !Access Denied!");
 return; // etc.
}
final int userID = result.getInt(1);
final String loginUser = result.getString(2);

It removes magic strings from the code and makes it easier to read.

Note that I moved the variable declarations too. (Effective Java, Second Edition, Item 45: Minimize the scope of local variables has a good overview on this topic. (Google for "minimize the scope of local variables", it's on Google Books too.))

3, Instead of the ResultSet.get*(int columnIndex) methods use the ResultSet.get*(String columnLabel) ones:

userID = result.getInt("UserID");
loginUser = result.getString("Username);

It also removes some magic numbers from the code and makes it easier to read.

4,

PrintWriter wr = response.getWriter ();

should be

PrintWriter wr = response.getWriter();

From http://www.oracle.com/technetwork/java/codeconventions-141388.html#475

Note that a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

5, I'd use longer variable names:

PrintWriter writer = response.getWriter();

It's more readable.

lang-java

AltStyle によって変換されたページ (->オリジナル) /