savepicture.java

来自「由浅入深的介绍JAVAse的基本编程思想」· Java 代码 · 共 42 行

JAVA
42
字号
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();
			}		
		}		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?