当前位置: 代码迷 >> Java相关 >> Mysql这问题还是不能解决,非连接问题!!!
  详细解决方案

Mysql这问题还是不能解决,非连接问题!!!

热度:340   发布时间:2011-09-13 20:50:51.0
Mysql这问题还是不能解决,非连接问题!!!

源代码“

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class BlobDemo1{
   private static  final String Driver="org.gjt.mm.mysql.Driver";
   private static  final String dburl="jdbc:mysql://localhost:3306/justhin";
   private static  final String user="root";
   private static  final String password="admin";
public static void main(String args[]) throws Exception{
     Connection con=null;
     PreparedStatement psmt=null;
    // ResultSet rs=null;
     
     String name="平南";
     String sql="insert into blob1(name,movies) values(?,?)";
     
     Class.forName(Driver);
     con=DriverManager.getConnection(dburl,user,password);
     psmt=con.prepareStatement(sql);
     File f=new File("F:"+File.separator+"20110821482.jpg");
     InputStream input=null;
     input=new FileInputStream(f);
     psmt.setString(1,name);
     psmt.setBinaryStream(2,input,(int)f.length());
     psmt.executeUpdate();
     input.close();
     psmt.close();
     con.close();
  }
}运行报错:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExce
tion: You have an error in your SQL syntax; check the manual that corresponds t
your MySQL server version for the right syntax to use near 'd?e?\"#U?)laj°?
I%?è????íòJ?íe??L??9?\0??hkà@}?7/???\'     {??M?2LkO??÷?D?à??' at line 1
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown So
rce)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.Util.getInstance(Util.java:381)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.j
va:1734)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.jav
:2019)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.jav
:1937)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.jav
:1922)
        at BlobDemo1.main(BlobDemo1.java:30)
数据库:     
mysql> desc blob1;
+--------+-------------+------+-----+---------+----------------+
| Field  | Type        | Null | Key | Default | Extra          |
+--------+-------------+------+-----+---------+----------------+
| id     | int(11)     | NO   | PRI | NULL    | auto_increment |
| name   | varchar(30) | NO   |     |         |                |
| movies | longblob    | YES  |     | NULL    |                |
+--------+-------------+------+-----+---------+----------------+

----------------解决方案--------------------------------------------------------
这个问题我也看不懂
----------------解决方案--------------------------------------------------------
id是没有加。。。
----------------解决方案--------------------------------------------------------
你把表重新建下。。确定加上 auto_increment
才能省略不加id
----------------解决方案--------------------------------------------------------
这货不是代码、把能删的都删了,剩下最简单的连接数据库的四步看看行不行,如果不行就是数据库的问题了
----------------解决方案--------------------------------------------------------
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExce
看清楚异常MySQLSyntaxErrorExce
mysql语法错误


----------------解决方案--------------------------------------------------------
  相关解决方案