Jump to content

Help With Jdbc Java Program


zaheer

Recommended Posts

Hi,I'm trying to develop a JDBC program to interact with an SQL Server running PostGres. I'm curious as to whether the following will work:String query = "SELECT CARNAME FROM CAR WHERE " + "CARYEAR=this.year";ResultSet rs= stmt.executeQuery(query);In the above within the query I used "this.year" which is a variable stored within the JDBC java program. Will this work???

Link to comment
Share on other sites

You have to concatenate the year property onto the string, or else it will pass this.year literally to ProgreSQL and that will try to find the `year` column in the `this` table.

String query = "SELECT CARNAME FROM CAR WHERE " +"CARYEAR=" + this.year;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...