如何纠正这一错误? [英] How to correct this error?

查看:147
本文介绍了如何纠正这一错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android应用程序,我使用REST风格的Webservices.I已经使用multiPartEntity从客户端向server.I发送数据没有在客户端的任何错误side.but我在服务器端$ C $有错误c.can你能帮我吗?

I am developing android App and I am using RestFul Webservices.I have used multiPartEntity to send data from client side to server.I don't have any error in client side.but I have error in my server side code.can you help me?

我的客户端code是:

                    multipart.addPart("hotelName",new StringBody(hotelName));
                    multipart.addPart("userName",new StringBody(userName));
                    multipart.addPart("password",new StringBody(password));
                    multipart.addPart("tinNumber",new StringBody(tinNumber));
                    multipart.addPart("Address",new StringBody(Address));
                    multipart.addPart("mobile_No",new StringBody(mobile_No));
                    multipart.addPart("email_Id",new StringBody(email_Id));
                    multipart.addPart("star_Rate",new StringBody(star_Rate));                       
                    multipart.addPart("imagePath",new InputStreamBody(getContentResolver().openInputStream(Uri.parse("file://"+imagePath)),imageName+".jpg"));

                    httppost.setEntity(multipart);
                    response = httpclient.execute(httppost);

我的服务器端code是

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public void postHotel(MultiPart hotelParams)
        throws SQLException, FileNotFoundException, IOException {

            stmt.executeUpdate("insert into hotel (name,user_name,password,tin_number,address,mobile_no,email,rating,hotel_logo) values('"
            +hotelParams.getBodyParts().get(0)
            + "','"
            + hotelParams.getBodyParts().get(1)
            + "','"
            + hotelParams.getBodyParts().get(2)
            + "',"
            + hotelParams.getBodyParts().get(3)
            + ",'"
            + hotelParams.getBodyParts().get(4)
            + "',"
            + hotelParams.getBodyParts().get(5)
            + ",'"
            + hotelParams.getBodyParts().get(6)
            + "','"
            + hotelParams.getBodyParts().get(7) + "','" + hotelParams.getBodyParts().get(8) + "');");

我的错误是这样的:

SERVE: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near '.multipart.FormDataBodyPart@9d2f26,'com.sun.jersey.multipart.FormDataBodyPart@18' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.Util.getInstance(Util.java:384)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583)
    at com.orderfree.Resource.HotelRegsiter.postHotel(HotelRegsiter.java:98)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

请帮我的朋友

推荐答案

这是一个SQL语法错误尝试打印 hotelParams.getBodyParts()得到(0)

It is a sql syntax error try to print the values of hotelParams.getBodyParts().get(0)

hotelParams.getBodyParts()获取(1)

1.Try检查是否你得到的字符串或没有。

1.Try to Check whether you are getting strings or not.

2.Try检查空格在SQL查询的

2.Try to check whitespaces in between sql query

3.Try通过把这样的事情乌尔编辑code

3.Try to edit ur code by putting something like this

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public void postHotel(@FormDataParam("user_name") String userName
                   @FormDataParam("password") String password)
        throws SQLException, FileNotFoundException, IOException {

            stmt.executeUpdate("insert into hotel(user_name,password)values('"
            +userName
            + "','"
            +password
            + "');

这篇关于如何纠正这一错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆