If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > java.SQLException: bind variable doesnot exist

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-27-10, 02:35
dg1069 dg1069 is offline
Registered User
 
Join Date: Apr 2010
Posts: 13
java.SQLException: bind variable doesnot exist

Hi,

I am trying to execute a select query using prepared statement in java. The executeQuery() method throws bind variable doesnot exist exception. Below is the code section for the same.

Code:
String var_a = "12345";
String  sql = "select distinct (SELECT Col_1 FROM Col_ATTRIBUTE WHERE  Col_2 ='AB' and Col_3 = ?) AS COL_NAME, " +  
					   "(DECODE((select distinct \"Col_1\" from Tab_1 where Col_3 = ? AND \"Col_1\" = 'Open'),'Open',1, 0)) AS COL_STAT, " +
					   "(Select SUM(\"Col_B\") from Tab_2 where Col_2 = ? AND \"Col_3\" = 'Open') AS COL_B from DUAL";

stmt = conn.prepareStatement(sql);
		counter = 0;
		try
		{
			while (counter <= 3)
			{
				stmt.setString(++counter,var_a);
			}
			log.debug("Query : " + stmt.toString());
		}
		catch (Exception e)
		{
			log.error("Exception :"+e);
		}

		try
		{
			ResultSet  rs = stmt.executeQuery();
			log.debug("After query execution..." );
				if(!rs.next())
				{
					log.debug("No records");
				} else {
				while(rs.next())
				{
					log.debug("Inside the while loop..." );
					varName = rs.getString(1);				             }
			}
		}
		catch (Exception e)
		{
			log.error("Exception :"+e);
		}
		finally
		{
			if(rs!=null){
			rs.close();
			stmt.close();
			}
		}
Please advice how to resolve this issue. I am using java1.4.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On