java mysql blob 写入
importjava.io.FileInputStream;importjava.io.InputStream;importjava.sql.Connection;imp...
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
public class BlobDemo {
public static final String driver = "com.mysql.jdbc.Driver";
public static final String url = "jdbc:mysql://localhost:3306/nnnn";
public static final String user = "root";
public static final String password = "mysqladmin";
public static void main(String[] args)throws Exception{
Connection con = null;
java.sql.PreparedStatement ps =null;
String name = "n";
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
ps = con.prepareStatement("insert into userblob(name,photo) values(?,?)");
InputStream input = new FileInputStream("d:\\n.jpg");
ps.setString(1, name);
ps.setBinaryStream(2, input,input.available());
ps.executeUpdate();
ps.close();
con.close();
}
}
总是报错,不懂问题出在哪里 展开
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
public class BlobDemo {
public static final String driver = "com.mysql.jdbc.Driver";
public static final String url = "jdbc:mysql://localhost:3306/nnnn";
public static final String user = "root";
public static final String password = "mysqladmin";
public static void main(String[] args)throws Exception{
Connection con = null;
java.sql.PreparedStatement ps =null;
String name = "n";
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
ps = con.prepareStatement("insert into userblob(name,photo) values(?,?)");
InputStream input = new FileInputStream("d:\\n.jpg");
ps.setString(1, name);
ps.setBinaryStream(2, input,input.available());
ps.executeUpdate();
ps.close();
con.close();
}
}
总是报错,不懂问题出在哪里 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询