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()) {

                }
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by javaAddict
Featured Replies
  • [QUOTE=poojavb;1757567]Check if the connection is created to the database [CODE] 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 } [/CODE][/QUOTE] That is not what [I]TIM_M_91[/I] has asked. @TIM_M_91: It is odd that you haven't found the correct syntax because … Read More

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
}
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.