Hi,

I am new to mysql and have got a problem. I have managed to INSERT into the database and and check from it (a simple login system) but now after i login i want to copy all the data from that row and throw it into an arraylist.

I tried something like this to simply get a field from the db and put it in a local variable, but its returning the error : No ResultSet was produced.

ResultSet st = statement.executeQuery("select `clientname` into @name from clients where username='" + Login.username + "' and password = '" + Login.password + "'");

Recommended Answers

All 9 Replies

Is that your message or is that a real exception message?

Also, do not cobble together statements like this. Use a PreparedStatement and its set... methods to include the username and password or you are just asking for problems.

I can't say anything about that "into @name" syntax since I don't recognise it, but MySQL does do some strange things, so who knows.

One thing I do know about MySQL, though, is that if that password field is a "password" field and not just a char/varchar/text field, then MySQL will have digested that password and a digest string will exist in that field, not the actually entered text.

I just want to get a field called "ClientName" from the database where the username is "username" (getting that from a textfield) and put this "ClientName" in a variable to use in the program. I dont think its complicated but I have only been doing sql for a few days and this is all i have learnt from the web.

Thanks

Okay? And that stops you from posting the exception and searching for the term "PreparedStatement", how?

ok man forget it ... i figured it out... and when answering a newbie's post please try going down to their level and explain what you say not pretending anyone understands you.

Thanks anyway.. cheers

As even a newbie should know, if you don't understand something someone tells you, then you need to tell them what it is you didn't understand not just, essentially, repeat the original question. And, when the subject is technical, then even a newbie should know to pick out the key terms and google them rather than just capitulate. As a programmer you will constantly be confronted with things you don't know but will be expected to be able to do them, or at least to figure them out, on your own.

Hi masijade,

i do want ur tip regarding how to retreive the data from mysql and placing it in an arraylist in java code.

actually i should fetch data from a table and store it in arraylist and populating the datagrid in flex using those values. so how to get the values from sql and store it in array list in java.

i had done like this

while(rs.next()) 
		    {
                           System.out.println("hai stupid");
		    	B.add(rs.getInt("Ticket_ID"));
		    	C.add(rs.getString("MODIFIED_ON"));
		    	D.add(rs.getString("SEVERITY"));
		    	E.add(rs.getString("E_MAIL"));
		    	F.add(rs.getString("IP"));
		    	System.out.println("hai         ");
		    	
		    	
		    	abc.add(0,B);
		    	abc.add(1,C);
		    	abc.add(2,D);
		    	abc.add(3,E);
		    	abc.add(4,F);
		    }

where B,C,D,E,F are the array list's and finally am returning abc which is also an array list.

My datagrid in flex is not populating if i do it in this way.

thanks & regards,
asha

create an object array of the same length as the resultset has columns and then get... into the array indexes (the array index is, of course, one less than resultset index) and then add that array to the list.

:) thanks for the reply masijade but i have faced 2 new issues now

1. all my data types are not string type

2. i have to populate multiple row values in row manner one after the other but it is coming in column manner.

wtg for ur reply.

create an object array of the same length as the resultset has columns and then get... into the array indexes (the array index is, of course, one less than resultset index) and then add that array to the list.

That is why I said Object array. And int will autobox to an Integer when added to an Object[] index. Likewise with Long, Double, etc, and, obviously, you can Store Date, Timestamp, etc, in an Object[] array as well.

For the second issue, if you mean you have to populate column one in all rows, then column 2 in all rows, then you probably have a design problem. If you mean you have to populate an entire row at once, well, that is what you get from a result set anyway, and exactly what a List<Object[]> (which is what I suggested) also gives you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.