Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Main {
    public static void main(String[] argv) throws Exception {
        File file = new File("myimage.gif");
        FileInputStream fis = new FileInputStream(file);
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//server.local:1521/prod", "scott",
                "tiger");
        conn.setAutoCommit(false);
        PreparedStatement ps = conn.prepareStatement("insert into images values (?,?)");
        ps.setString(1, file.getName());
        ps.setBinaryStream(2, fis, (int) file.length());
        ps.executeUpdate();
        ps.close();
        fis.close();

    }
}