我的一个jsp部分代码,其中id是上一个页面传过来的参数(数据库查询得到的动态数据): String id;
try
{
id= request.getParameter("id");
}catch(Exception e){
id="wrong";
}
%>
<%
String DBURL="jdbc:postgresql://localhost/postgres";
String user="postgres";
String password="postgres";
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
String sqlString1=null;
try{
Class.forName("org.postgresql.Driver").newInstance();
con=DriverManager.getConnection(DBURL,user,password);
}catch(ClassNotFoundException e){
out.println("ClassNotFoundException:"+e.getMessage());
}
if(id!="wrong"){
sqlString1="select office_id,company_name,line_1_label_address,line_2_label_address,line_3_label_address,line_4_label_address,line_5_label_address,postal_code,telephone,facsimile,email from xinaddress where company_name="+id;我运行时,我从上一个页面进这个页面时总是出现错误,
说
SQL Exception!:ERROR: syntax error at or near "Shipping"
但是我如果传的参数是int类型时
上面用
int id;
try
{
id= Integer.parseInt(request.getParameter("id"));
}catch(Exception e){
id=0;
}
就没有错,在我的页面里面传的参数是string类型的,是不是也需要加integer.parseInt()类似的东西呢?
怎么加,加什么?
我这个不太懂啊?
大家帮帮忙!
try
{
id= request.getParameter("id");
}catch(Exception e){
id="wrong";
}
%>
<%
String DBURL="jdbc:postgresql://localhost/postgres";
String user="postgres";
String password="postgres";
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
String sqlString1=null;
try{
Class.forName("org.postgresql.Driver").newInstance();
con=DriverManager.getConnection(DBURL,user,password);
}catch(ClassNotFoundException e){
out.println("ClassNotFoundException:"+e.getMessage());
}
if(id!="wrong"){
sqlString1="select office_id,company_name,line_1_label_address,line_2_label_address,line_3_label_address,line_4_label_address,line_5_label_address,postal_code,telephone,facsimile,email from xinaddress where company_name="+id;我运行时,我从上一个页面进这个页面时总是出现错误,
说
SQL Exception!:ERROR: syntax error at or near "Shipping"
但是我如果传的参数是int类型时
上面用
int id;
try
{
id= Integer.parseInt(request.getParameter("id"));
}catch(Exception e){
id=0;
}
就没有错,在我的页面里面传的参数是string类型的,是不是也需要加integer.parseInt()类似的东西呢?
怎么加,加什么?
我这个不太懂啊?
大家帮帮忙!
解决方案 »
- 关于Vector.add中的覆盖问题
- 如何在页面加载的时候不显示页面的内容,只显示一个提示对话框?
- 如何用js实现页面弹出窗口 页面变透明样子?
- 向servlet中提交表单时出现的 问题
- input输入框,按回车键调用一函数submit,可现在却只有"当"的一声
- 谁有jakarta-tomcat-4.1.30.exe,200分当场拿走!
- 如何判断指定文件是否存在?
- ISO-8859-1和GBK是什么区别
- 写了一个操作数据库的问题:用火狐可以添加成功,IE不成功,不知道怎么回事?
- 哪儿有CVS新版本下载,window2000用的,谢谢!!不然死掉了!!!!
- servlet 新手问题
- jsp 内建对象何时被创建 何时被销毁
应该改成where company_name='"+id+"'"