cancel
Showing results for 
Search instead for 
Did you mean: 

SQL 2005 , Where condition in Select statement

Former Member
0 Kudos

Hi All

i am using SQL Server 2005 as a backend for webservices, i want to select the data based on the user input in where condition,

SELECT [NO]
      ,[NAME]
      ,[PAGE_COUNT]
  FROM [DS].[DB].[tablename]
where [NO]=???

Ex: i will pass the NO to the webservice to get the respective data from SQL,but i am not sure what operand to give in where condition,does anybody have idea on this

Thanks and Regards

Chaitanya.A

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Make use of prepared statements

http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

Regards

Ayyapparaj

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sudhir / Ayyapparaj

The query which i posted is the same which i am using in SQL ( along with square brackets)

i am tryting to execute the same query using the options provided by you in SQL 2005 ,even then i am not getting any prompt to enter input.

first i want to test in SQL and then implement in webdynpro.

Thanks

Chaitanya.A

Former Member
0 Kudos

Hi,

If you are trying it in query analyser of the MSSql server

You have to provide the values and then execute the query.

Ex:

SELECT [NO]

,[NAME]

,[PAGE_COUNT]

FROM [DS].[DB].[tablename]

where [NO]=1

Regards

Ayyapparaj

Former Member
0 Kudos

HI

public String getEmployeeName(String employeeNumber) 
	{
		// TODO : Implement
		String name = new String();
		String exception = new String();
		try 
		{
		InitialContext initialContext = new InitialContext();
		DataSource dataSource =(DataSource) initialContext.lookup("jdbc/XXXX");
		java.sql.Connection connection = dataSource.getConnection();
		PreparedStatement stmt =connection.prepareStatement("SELECT [NAME]FROM [XXX].[ASDF].[ABCD] where [NO]=?");
		stmt.setString(1,employeeNumber);
		ResultSet result = stmt.executeQuery();
		while (result.next()) 
			{
			name = result.getString("Name");
			}
			connection.close();
			return name;
		}
		catch (Exception e) 
		{
			exception = "Exception";
			return exception;
		}
	}

i used the above function to achieve my requirement

Thanks

Chaitanya.A

Former Member
0 Kudos

Hi,

PreparedStatement stmt = null;

String query="SELECT [NO]

,[NAME]

,[PAGE_COUNT]

FROM [DS].[DB].[tablename]

where [NO]=?";

stmt = con.prepareStatement(QUERY);

stmt.setInt(1, no);

rs = stmt.executeQuery();

where "no" is the number which you get from webservive.

Regards,

Sudhir