| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 589 人关注过本帖
标题:Mysql这问题还是不能解决,非连接问题!!!
只看楼主 加入收藏
w123012306
Rank: 9Rank: 9Rank: 9
来 自:湖南
等 级:蜘蛛侠
威 望:4
帖 子:307
专家分:1180
注 册:2010-4-22
结帖率:90%
收藏
已结贴  问题点数:0 回复次数:5 
Mysql这问题还是不能解决,非连接问题!!!

源代码“

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.SQLException;
import
import
import

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    |                |
+--------+-------------+------+-----+---------+----------------+
搜索更多相关主题的帖子: localhost password private 源代码 public 
2011-09-13 20:50
章文2010
Rank: 2
等 级:论坛游民
帖 子:6
专家分:14
注 册:2011-8-18
收藏
得分:0 
这个问题我也看不懂
2011-09-14 17:14
husiwen
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:227
专家分:1125
注 册:2010-5-23
收藏
得分:0 
id是没有加。。。
2011-09-14 18:15
husiwen
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:227
专家分:1125
注 册:2010-5-23
收藏
得分:0 
你把表重新建下。。确定加上 auto_increment
才能省略不加id
2011-09-14 18:18
刘杰明
Rank: 8Rank: 8
来 自:山东大学威海校区
等 级:蝙蝠侠
帖 子:155
专家分:872
注 册:2011-6-20
收藏
得分:0 
这货不是代码、把能删的都删了,剩下最简单的连接数据库的四步看看行不行,如果不行就是数据库的问题了

______________________________加油__!__!___!
2011-09-15 08:35
鱼骨头Main
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:55
专家分:138
注 册:2009-3-27
收藏
得分:50 
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExce
看清楚异常MySQLSyntaxErrorExce
mysql语法错误

2011-09-16 10:27
快速回复:Mysql这问题还是不能解决,非连接问题!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019558 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved