当前位置: 技术问答>java相关
高分求助:在oracle中保存图片问题
来源: 互联网 发布时间:2015-08-26
本文导语: 以下是我的一段程序:请问各位大虾帮我找出错误: 表结构:(oracle) CREATE TABLE SYSTEM.HRMACH_CONTRACT_PHOTO ( ARCHIVE_CD VARCHAR2(11) NOT NULL, CONTRACT ...
以下是我的一段程序:请问各位大虾帮我找出错误:
表结构:(oracle)
CREATE TABLE SYSTEM.HRMACH_CONTRACT_PHOTO
(
ARCHIVE_CD VARCHAR2(11) NOT NULL,
CONTRACT BLOB,
PHOTO BLOB,
CONSTRAINT PK_HRMACH_CONTRACT_PHOTO PRIMARY KEY (ARCHIVE_CD)
)
import oracle.jdbc.driver.*;
import java.sql.*;
import java.io.*;
public class Untitled1
{
public static void main(String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.168:1521:imart ","system","manager");
PreparedStatement ps = conn.prepareStatement("INSERT INTO HRMACH_CONTRACT_PHOTO(ARCHIVE_CD,PHOTO) values (?,?)");
//ps.setInt(1,1);
ps.setString(1,"33333334");
File inFile = new File("c:\5.jpg");
int length=(int) inFile.length();
FileInputStream inFileStream =new FileInputStream(inFile);
ps.setBinaryStream(1,inFileStream,length);
ps.execute();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();}
}
}
执行结果:
java.sql.SQLException: ORA-01008: 并非所有变量都已关联
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:822)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1446)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1371)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1900)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:407)
at com.borland.samples.welcome.Untitled1.main(Untitled1.java:32)
表结构:(oracle)
CREATE TABLE SYSTEM.HRMACH_CONTRACT_PHOTO
(
ARCHIVE_CD VARCHAR2(11) NOT NULL,
CONTRACT BLOB,
PHOTO BLOB,
CONSTRAINT PK_HRMACH_CONTRACT_PHOTO PRIMARY KEY (ARCHIVE_CD)
)
import oracle.jdbc.driver.*;
import java.sql.*;
import java.io.*;
public class Untitled1
{
public static void main(String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.168:1521:imart ","system","manager");
PreparedStatement ps = conn.prepareStatement("INSERT INTO HRMACH_CONTRACT_PHOTO(ARCHIVE_CD,PHOTO) values (?,?)");
//ps.setInt(1,1);
ps.setString(1,"33333334");
File inFile = new File("c:\5.jpg");
int length=(int) inFile.length();
FileInputStream inFileStream =new FileInputStream(inFile);
ps.setBinaryStream(1,inFileStream,length);
ps.execute();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();}
}
}
执行结果:
java.sql.SQLException: ORA-01008: 并非所有变量都已关联
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:822)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1446)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1371)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1900)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:407)
at com.borland.samples.welcome.Untitled1.main(Untitled1.java:32)
|
参考:
http://www.csdn.net/expert/topic/876/876147.xml?temp=.1455652
http://www.csdn.net/expert/topic/876/876147.xml?temp=.1455652
|
ps.setBinaryStream(1,inFileStream,length);
改为:
ps.setBinaryStream(2,inFileStream,length);
改为:
ps.setBinaryStream(2,inFileStream,length);
|
up