import java.sql.*;
import java.io.*;
public class SavePicture{
public static void main(String[] args){
Connection conn = null;
PreparedStatement stmt = null;
FileInputStream fis = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql = "insert into Student_List values(?,?,?)";
stmt=conn.prepareStatement(sql);
stmt.setString(1, "s01");
stmt.setString(2, "Youyou");
File file = new File( "yy.jpg");
fis = new FileInputStream(file);
stmt.setBinaryStream(3, fis, ( int)file.length());
stmt.executeUpdate();
stmt.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(fis!= null){
fis.close();
}
} catch(IOException ioe){
ioe.printStackTrace();
}
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.io.*;
public class SavePicture{
public static void main(String[] args){
Connection conn = null;
PreparedStatement stmt = null;
FileInputStream fis = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql = "insert into Student_List values(?,?,?)";
stmt=conn.prepareStatement(sql);
stmt.setString(1, "s01");
stmt.setString(2, "Youyou");
File file = new File( "yy.jpg");
fis = new FileInputStream(file);
stmt.setBinaryStream(3, fis, ( int)file.length());
stmt.executeUpdate();
stmt.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(fis!= null){
fis.close();
}
} catch(IOException ioe){
ioe.printStackTrace();
}
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.sql.*;
import java.io.*;
public class GetPicture{
public static void main(String[] args){
PreparedStatement stmt = null;
ResultSet rs = null;
Connection conn = null;
FileOutputStream fos = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url= "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql= "select * from Student_List where Student_ID='s01'";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
rs.next();
File file = new File( "d:\\kk.jpg");
fos = new FileOutputStream(file);
InputStream is = rs.getBinaryStream(3);
int len = 0;
byte b[] = new byte[4*1024];
while((len=is.read(b))!=-1)
{
fos.write(b,0,len);
}
fos.flush();
fos.close();
is.close();
rs.close();
stmt.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(fos!= null){
fos.close();
}
} catch(IOException ioe){
ioe.printStackTrace();
}
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.io.*;
public class GetPicture{
public static void main(String[] args){
PreparedStatement stmt = null;
ResultSet rs = null;
Connection conn = null;
FileOutputStream fos = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url= "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql= "select * from Student_List where Student_ID='s01'";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
rs.next();
File file = new File( "d:\\kk.jpg");
fos = new FileOutputStream(file);
InputStream is = rs.getBinaryStream(3);
int len = 0;
byte b[] = new byte[4*1024];
while((len=is.read(b))!=-1)
{
fos.write(b,0,len);
}
fos.flush();
fos.close();
is.close();
rs.close();
stmt.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(fos!= null){
fos.close();
}
} catch(IOException ioe){
ioe.printStackTrace();
}
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.sql.*;
import java.io.*;
public class SaveClob{
public static void main(String[] args){
Connection conn = null;
PreparedStatement stmt = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql = "insert into book_list values(?,?,?)";
stmt=conn.prepareStatement(sql);
stmt.setString(1, "b001");
stmt.setString(2, "99个简单法则");
BufferedReader br = new BufferedReader( new FileReader( "a.txt"));
StringBuffer sb = new StringBuffer();
String s;
while((s=br.readLine()) != null){
sb.append(s + "\n");
}
br.close();
String content = sb.toString();
StringReader sr = new StringReader(content);
stmt.setCharacterStream(3, sr, content.length());
stmt.executeUpdate();
sr.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.io.*;
public class SaveClob{
public static void main(String[] args){
Connection conn = null;
PreparedStatement stmt = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql = "insert into book_list values(?,?,?)";
stmt=conn.prepareStatement(sql);
stmt.setString(1, "b001");
stmt.setString(2, "99个简单法则");
BufferedReader br = new BufferedReader( new FileReader( "a.txt"));
StringBuffer sb = new StringBuffer();
String s;
while((s=br.readLine()) != null){
sb.append(s + "\n");
}
br.close();
String content = sb.toString();
StringReader sr = new StringReader(content);
stmt.setCharacterStream(3, sr, content.length());
stmt.executeUpdate();
sr.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.sql.*;
import java.io.*;
public class GetClob{
public static void main(String[] args){
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
FileOutputStream fos = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url= "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql= "select * from book_list where bid='b001'";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
rs.next();
StringBuffer sb = new StringBuffer();
Reader rd = rs.getCharacterStream(3);
BufferedReader br = new BufferedReader(rd);
String s;
while((s=br.readLine())!= null)
{
sb.append(s + "\n");
}
System.out.println(sb.toString());
rs.close();
br.close();
stmt.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.io.*;
public class GetClob{
public static void main(String[] args){
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
FileOutputStream fos = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver");
String url= "jdbc:oracle:thin:@localhost:1521:ora9";
conn = DriverManager.getConnection(url, "scott", "tiger");
String sql= "select * from book_list where bid='b001'";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
rs.next();
StringBuffer sb = new StringBuffer();
Reader rd = rs.getCharacterStream(3);
BufferedReader br = new BufferedReader(rd);
String s;
while((s=br.readLine())!= null)
{
sb.append(s + "\n");
}
System.out.println(sb.toString());
rs.close();
br.close();
stmt.close();
} catch(Exception e){
e.printStackTrace();
} finally{
try{
if(conn != null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}
}