error in my jsp code

<%@ page language ="java"import ="java.sql.*" %>

<%@ pageimport ="java.sql.*" %>

<%@ pageimport ="java.text.*" %>

<%

//String stin,btin,pname,pcount,tax;

String stin=request.getParameter("sellertin");

session.setAttribute("sellertin",stin);

String btin=request.getParameter("buyertin");

session.setAttribute("buyertin",btin);

String pname=request.getParameter("prodname");

session.setAttribute("prodname",pname);

String pcount=request.getParameter("prodcount");

session.setAttribute("prodcount",pcount);

String tax=request.getParameter("vat");

session.setAttribute("vat",tax);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String st ="jdbc:odbc:loginval";

Connection cn = DriverManager.getConnection(st," "," ");

Statement stmt = cn.createStatement();

stin=stin+"prod";

String str ="select * from '"+stin+"' where proname='"+pname+"'" ;

ResultSet result1 = stmt.executeQuery(str);

String pron,prop,proc;

pron = result1.getString("proname");

prop = result1.getString("proprice");

proc = result1.getString("procount");

int rate,price,ntax,net,ncount;

price=Integer.parseInt(prop);

ntax=Integer.parseInt(tax);

rate=price+(price*(ntax/100));

ncount=Integer.parseInt(pcount);

net=rate*ncount;

%>

the tax is calculated as<%=net%>

in this code i am trying to dynamically select different tables based on the user input. nut the program does not execute properly.

i get an error as follows

syntax error in query:incomplete query clause.

some one plz find where i ve gone wrong.

thanks in advance

[2554 byte] By [kiranmea] at [2007-11-26 21:03:55]
# 1
Print out the SQL statement and try to run it against the dtatabase using a tool like DBVisualizer.Once you get the SQL working you can fix the Java code that creates it.
tolmanka at 2007-7-10 2:36:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
only the select query is not working, i have tried other sql queries like, insert , create etc. they are working just fine, only this is not working properly.is there any other way to select the table dynamically?
kiranmea at 2007-7-10 2:36:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
http://www.jyog.com/forum
Sudhir_nimavata at 2007-7-10 2:36:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> only the select query is not working, i have tried

> other sql queries like, insert , create etc. they are

> working just fine, only this is not working

> properly.

>

> is there any other way to select the table

> dynamically?

The SQL query has some mistakes:

"select * from '"+stin+"' where proname='"+pname+"'" ;

Why is the table name also in single quotes?

It shouldn't be.

Try this:

"select * from "+stin+" where proname='"+pname+"'" ;

appy77a at 2007-7-10 2:36:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

>>String str = "select * from '"+stin+"' where proname='"+pname+"'" ;

>>ResultSet result1 = stmt.executeQuery(str);

>>String pron,prop,proc;

>>pron = result1.getString("proname");

>>prop = result1.getString("proprice");

>>proc = result1.getString("procount");

You can not just access the result set like that you need to call the next method.

ResultSet result1 = stmt.executeQuery(str);

String pron,prop,proc;

if (result1.next()) {

pron = result1.getString("proname");

prop = result1.getString("proprice");

proc = result1.getString("procount");

}

tolmanka at 2007-7-10 2:36:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Tablename should not be in single quote.Try thisString str = "select * from "+stin+" where proname='"+pname+"'" ;instead ofString str = "select * from '"+stin+"' where proname='"+pname+"'" ;
Mokshaa at 2007-7-10 2:36:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
thanks to each of u......its working really wellthanks a ton.
kiranmea at 2007-7-10 2:36:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...