java - MySql syntaxErrorException when manually building SQL query with AND or OR conditions -
i developing simple web appilcation using jsp,servlets , mysql. have table called annotations in mysql database. fetch records based on 'or' , 'and' mysql. unfortunately getting jdbc-mysql synatax exception. i'm composing sql query below:
dbconnection=new dbconnection(); connection=dbconnection.setconnection(); transcript_id=request.getparameter("transcript_id"); condition_1=request.getparameter("condition_1"); // can "or" or "and". gene_symbol=request.getparameter("gene_symbol"); condition_2=request.getparameter("condition_2"); // can "or" or "and". molecular_function=request.getparameter("molecular_function"); condition_3=request.getparameter("condition_3"); // can "or" or "and". biological_process=request.getparameter("biological_process"); stmt=connection.createstatement(); query="select * annotations id='"+transcript_id+"','"+condition_1+"',gene_symbol='"+gene_symbol+"','"+condition_2+"',"+ "molecular_function='"+molecular_function+"','"+condition_3+"',biological_process='"+biological_process+"'";
the error got in console is
you have error in sql syntax; check manual corresponds mysql server version right syntax use near ''or',gene_symbol='tmx3','or',molecular_function='','or',biological_process=''' @ line 1
could guide me mistake in sql syntax.
remove commas conditions
query="select * annotations id='"+transcript_id+"' "+condition_1+" gene_symbol='"+gene_symbol+"' "+condition_2+" "+ "molecular_function='"+molecular_function+"' "+condition_3+" biological_process='"+biological_process+"'";
Comments
Post a Comment