Hi all,
I have just changed my JDK, from 1.5.0 to 1.6.0, and also change my Netbeans, from NB 4.0 to NB 5.5. I've got a problem with my code, which I wrote on NB 4.0 + JDK 1.5.0.. I fail to put anything into my hashtable when I try the code on NB 5.5 + JDK 1.6.0. Here is the code: -
-
public Hashtable getIDUser (HttpServletRequest request, HttpServletResponse response, String sqlWhere, String namaUser)
-
throws SQLException, IOException {
-
ServletOutputStream out = response.getOutputStream();
-
-
String sqlGetUserID = "SELECT ID, Nama, Password FROM " + strTblUser + " ";
-
if (sqlWhere == null) {
-
sqlGetUserID = sqlGetUserID;
-
} else {
-
sqlGetUserID = sqlGetUserID + sqlWhere;
-
}
-
-
// check 1
-
out.println("sqlGetUserID : " + sqlGetUserID + "<br>");
-
-
int a = 1;
-
try {
-
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
-
Connection con1 = DriverManager.getConnection(DBurl, "", "");
-
Statement stmt1 = con1.createStatement();
-
ResultSet rs1 = stmt1.executeQuery(sqlGetUserID);
-
-
// check 2
-
ResultSetMetaData rsmd = rs1.getMetaData();
-
int colCount = rsmd.getColumnCount();
-
out.println("colCount: " + colCount + "<br>");
-
-
Hashtable HTArea = new Hashtable();
-
-
while (rs1.next()) {
-
HTArea.put(new Integer(a), rs1.getString(0));
-
a = a + 1;
-
}
-
-
// check 3
-
int isiHT;
-
isiHT = HTArea.size();
-
out.println("isiHT: " + isiHT + "<br>");
-
-
rs1.close();
-
stmt1.close();
-
con1.close();
-
return HTArea;
-
}
-
catch (SQLException se) {
-
/** just catch */
-
}
-
catch (java.lang.Exception ex) {
-
/** just catch */
-
}
-
return new Hashtable();
-
}
-
-
If you look at my code, you will see that I have put some lines to check the code. I have no problem with Check 1 and Check 2, but when I see Check 3, I know something was happen. There is nothing in my Hashtable. Did I do something wrong when I try to put ResultSet into my hashtable? Can someone help me? Thank you.
Regards,
Novan Ananda
4 2048
Hi all,
I have just changed my JDK, from 1.5.0 to 1.6.0, and also change my Netbeans, from NB 4.0 to NB 5.5. I've got a problem with my code, which I wrote on NB 4.0 + JDK 1.5.0.. I fail to put anything into my hashtable when I try the code on NB 5.5 + JDK 1.6.0. Here is the code: -
-
public Hashtable getIDUser (HttpServletRequest request, HttpServletResponse response, String sqlWhere, String namaUser)
-
throws SQLException, IOException {
-
ServletOutputStream out = response.getOutputStream();
-
-
String sqlGetUserID = "SELECT ID, Nama, Password FROM " + strTblUser + " ";
-
if (sqlWhere == null) {
-
sqlGetUserID = sqlGetUserID;
-
} else {
-
sqlGetUserID = sqlGetUserID + sqlWhere;
-
}
-
-
// check 1
-
out.println("sqlGetUserID : " + sqlGetUserID + "<br>");
-
-
int a = 1;
-
try {
-
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
-
Connection con1 = DriverManager.getConnection(DBurl, "", "");
-
Statement stmt1 = con1.createStatement();
-
ResultSet rs1 = stmt1.executeQuery(sqlGetUserID);
-
-
// check 2
-
ResultSetMetaData rsmd = rs1.getMetaData();
-
int colCount = rsmd.getColumnCount();
-
out.println("colCount: " + colCount + "<br>");
-
-
Hashtable HTArea = new Hashtable();
-
-
while (rs1.next()) {
-
HTArea.put(new Integer(a), rs1.getString(0));
-
a = a + 1;
-
}
-
-
// check 3
-
int isiHT;
-
isiHT = HTArea.size();
-
out.println("isiHT: " + isiHT + "<br>");
-
-
rs1.close();
-
stmt1.close();
-
con1.close();
-
return HTArea;
-
}
-
catch (SQLException se) {
-
/** just catch */
-
}
-
catch (java.lang.Exception ex) {
-
/** just catch */
-
}
-
return new Hashtable();
-
}
-
-
If you look at my code, you will see that I have put some lines to check the code. I have no problem with Check 1 and Check 2, but when I see Check 3, I know something was happen. There is nothing in my Hashtable. Did I do something wrong when I try to put ResultSet into my hashtable? Can someone help me? Thank you.
Regards,
Novan Ananda
You are returning a new (empty) hashtable at the end of your method. You should return the hashtable that you were adding stuff to.
-
Hashtable HTArea = new Hashtable();
-
-
while (rs1.next()) {
-
HTArea.put(new Integer(a), rs1.getString(0));
-
a = a + 1;
-
}
-
This throws an exception because column indexes start at one, not zero. At the
end (after the catch) you return an empty hash set.
kind regards,
Jos
- catch (SQLException se) {
-
/** just catch */
-
}
-
catch (java.lang.Exception ex) {
-
/** just catch */
-
}
Maybe it's my inner Buddhist, but I'm always looking for examples where a person's behaviour is also his immediate punishment ;-)
- catch (SQLException se) {
-
/** just catch */
-
}
-
catch (java.lang.Exception ex) {
-
/** just catch */
-
}
Maybe it's my inner Buddhist, but I'm always looking for examples where a person's behaviour is also his immediate punishment ;-)
Even atheists only muffle exceptions away for a very good reason and even then:
they document them.
kind regards,
Jos ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Oberon |
last post by:
My HashTable (Global.Games) is a static collection of objects of type
Game. A Game object has 8 fields (exposed as properties). The key to
the HashTable is also one of these fields (GameID, of type...
|
by: Fred |
last post by:
I'm trying to build a hashtable and a arraylist as object value
I'm not able to retrieve stored object from the hashtable.
Hashtable mp = new Hashtable(); // THE HASHTABLE
ArrayList...
|
by: Zeng |
last post by:
I finally narrowed down my code to this situation, quite a few (not all) of
my CMyClass objects got hold up after each run of this function via the
simple webpage that shows NumberEd editbox. My...
|
by: ad |
last post by:
I have a hash table like:
Hashtable myHT = new Hashtable();
myHT.Add("First", "Hello");
myHT.Add("Second", "World");
myHT.Add("Third", "!");
We can use key to find value like:
myHT -> "Hello"...
|
by: Eric |
last post by:
Hello,
I have the following dataset that I want to bind to a repeater to be
displayed as a table.
Owner Animal Volume
---------------------------
Eric Dog 6
Eric Cat ...
|
by: Sky |
last post by:
What makes something a valid DataSource? What methods/iterators/etc?
Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too
table structured for what I am...
|
by: WhiskyRomeo |
last post by:
I am trying to implement a webservice that returns a HashTable as a result
<WebMethod()> Public Function GetAppData() As Hashtable
Dim List As New Hashtable
'omitted code
Return List
End...
|
by: SevDer |
last post by:
Hi
We have a static hashtable that is located in another tier in our n-tiered
web application.
And we are storing big but not huge objects in this hashtable and the key to
the objects is...
|
by: Ashish Khandelwal |
last post by:
-----See below code,
string str = "blair";
string strValue = "ABC";
string str1 = "brainlessness";
string strValue1 = "XYZ";
int hash = str.GetHashCode() ; // Returns 175803953
int hash1 =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |