2 qq 31676873 qq_31676873 于 2016.03.07 10:52 提问

用MySql插入图片报错!!r如何解决

String sql="insert into image(tupian) values(?)";
Connection conn=null;
PreparedStatement ps=null;
try {
conn=getConnection();
ps=(PreparedStatement) conn.prepareStatement(sql);
ps.setBinaryStream(1, Thread.currentThread().getContextClassLoader().getResourceAsStream("meinv.bmp"));
ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(null!=conn){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

        if(null!=ps){
            try {
                ps.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

3个回答

qq_31676873
qq_31676873   2016.03.07 10:53

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 '媢?W]JM覑[*Ф8銖卤)h]贕gv,靣X湌}i(?奪J\0Z(?=IaT?黁L?枈Z\0)h????' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
at ThreadTest1.main(ThreadTest1.java:50)

这个报错的部分
u013596119
u013596119   Rxr 2016.03.07 11:07

把你sql表的结构发来看看吧,java这边貌似没啥问题,可能是你的sql语句的问题

lx624909677
lx624909677   Ds   Rxr 2016.03.07 15:51

那个路径中一堆乱码,是因为中文的?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!