try{
Class.forName("com.mysql.jdbc.Driver");//驱动的名称
Connection c=DriverManager.getConnection("jdbc:mysql://localhost/数据库名?user=用户名&password=密码");
//访问的数据库的帐号密码
Statement s=c.createStatement();
File f = new File("E:/aa/IMG0105A.jpg" );
try{
PreparedStatement pstm = c.prepareStatement("insert into imgp(name,img) values (?,?)");
InputStream is = new FileInputStream(f);
pstm.setString(1, "lm");
pstm.setBinaryStream(2, is, is.available());
int count = pstm.executeUpdate();
if(count>0){
System.out.println("插入成功");
}else{
System.out.println("插入失败");
}
is.close();
pstm.close();
c.close();
} catch (Exception e){
e.printStackTrace();
}
s.close();
}catch(Exception e){
System.out.println("chu");
e.printStackTrace();}//捕获异常
}
Class.forName("com.mysql.jdbc.Driver");//驱动的名称
Connection c=DriverManager.getConnection("jdbc:mysql://localhost/数据库名?user=用户名&password=密码");
//访问的数据库的帐号密码
Statement s=c.createStatement();
File f = new File("E:/aa/IMG0105A.jpg" );
try{
PreparedStatement pstm = c.prepareStatement("insert into imgp(name,img) values (?,?)");
InputStream is = new FileInputStream(f);
pstm.setString(1, "lm");
pstm.setBinaryStream(2, is, is.available());
int count = pstm.executeUpdate();
if(count>0){
System.out.println("插入成功");
}else{
System.out.println("插入失败");
}
is.close();
pstm.close();
c.close();
} catch (Exception e){
e.printStackTrace();
}
s.close();
}catch(Exception e){
System.out.println("chu");
e.printStackTrace();}//捕获异常
}