1,105,546 Community Members

Correct syntax for query filter

Member Avatar
TIM_M_91
Junior Poster in Training
92 posts since Feb 2012
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi guys well what I'm trying to do is produce a query that only produces the results which will match my director input. I have looked for the correct syntax and cannot seem to find it.

Any help would be appreciated

Code of my syntax below:

ResultSet results = myStatement.executeQuery
                        ("SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS");
                while (results.next()) {

                }
Member Avatar
poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 29 [?]
Q&As Helped to Solve: 78 [?]
Skill Endorsements: 9 [?]
 
0
 

Hi guys well what I'm trying to do is produce a query that only produces the results which will match my director input. I have looked for the correct syntax and cannot seem to find it.

Any help would be appreciated

Code of my syntax below:

ResultSet results = myStatement.executeQuery
                        ("SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS");
                while (results.next()) {

                }

Check if the connection is created to the database

Connection con;
Statement stmt=con.createStatement();
ResultSet rs=null;

String ss=("SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS");
rs=stmt.executeQuery(ss); 
while(rs.next())
{
//code goes here
}
Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
1
 

Check if the connection is created to the database

Connection con;
Statement stmt=con.createStatement();
ResultSet rs=null;

String ss=("SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS");
rs=stmt.executeQuery(ss); 
while(rs.next())
{
//code goes here
}

That is not what TIM_M_91 has asked.


@TIM_M_91:
It is odd that you haven't found the correct syntax because all you needed is some basic tutorials about sql: http://w3schools.com/sql/default.asp
Any way, you can add this to your query:

SELECT VIDEOID, VIDEONAME, DIRECTOR 
FROM VIDEOS
WHERE VIDEOID=[I]something[/I] AND VIDEONAME=[I]somethingelse[/I] ...

Instead of AND you can use OR

The columns that you use as filters don't need to be at the select. This query is valid for example:

SELECT VIDEONAME
FROM VIDEOS
WHERE VIDEOID=[I]something[/I]

If you want to put it in java, using the Statement interface (as in your code) you can try this:

String videoId = "some_value";

String ss="SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS";
ss += " WHERE VIDEOID='"+videoId+"'";

System.out.println("Executing query:"+ss);

rs=stmt.executeQuery(ss);

What's out for the single quotes ' . The value of the ss is the query executed so print it and see what you have.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: