Some other notes:
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).
Instead of checking that
iUserID
is-1
or not check the result ofresult.next()
and set aboolean
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.))
Instead of the
ResultSet.get*(int columnIndex)
methods use theResultSet.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.
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.
I'd use longer variable names for readability:
PrintWriter writer = response.getWriter();
Some other notes:
Don't mix naming styles:
String DataURL = "jdbc:db://localhost:5112/users"; String loginName = "stackoverflow"
Variable names should be camelCase
(with lowercase first letter).
Instead of checking that
iUserID
is-1
or not check the result ofresult.next()
and set aboolean
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.))
Instead of the
ResultSet.get*(int columnIndex)
methods use theResultSet.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.
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.
I'd use longer variable names for readability:
PrintWriter writer = response.getWriter();
Some other notes:
Don't mix naming styles:
String DataURL = "jdbc:db://localhost:5112/users"; String loginName = "stackoverflow"
Variable names should be camelCase
(with lowercase first letter).
Instead of checking that
iUserID
is-1
or not check the result ofresult.next()
and set aboolean
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.))
Instead of the
ResultSet.get*(int columnIndex)
methods use theResultSet.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.
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.
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"
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).http://stackoverflow.com/questions/2082729/to-camelcase-or-not-to-camel-case
Instead of checking that
iUserID
is-1
or not check the result ofresult.next()
and set aboolean
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);
Instead of the
ResultSet.get*(int columnIndex)
methods use theResultSet.get*(String columnLabel)
ones:userID = result.getInt("UserID"); loginUser = result.getString("Username);
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.
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.
Don't mix naming styles:
String DataURL = "jdbc:db://localhost:5112/users"; String loginName = "stackoverflow"
Variable names should be camelCase
(with lowercase first letter).
Instead of checking that
iUserID
is-1
or not check the result ofresult.next()
and set aboolean
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.))
Instead of the
ResultSet.get*(int columnIndex)
methods use theResultSet.get*(String columnLabel)
ones:userID = result.getInt("UserID"); loginUser = result.getString("Username);
This:
PrintWriter wr = response.getWriter ();
should be:
PrintWriter wr = response.getWriter();
(From here ):
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).
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.