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

                }

Recommended Answers

All 2 Replies

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
}

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.

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.