0% found this document useful (0 votes)
25 views1 page

Store BLOB Data Into Database

This code connects to an Oracle database using JDBC, prepares an INSERT statement to add a record to a "pictures" table with a name, description, and image file, sets the parameter values, inserts the record into the database, and commits and closes the connection. It imports necessary Java classes, defines the database connection details, loads the Oracle driver, gets a connection, sets auto-commit to false, prepares the INSERT statement, sets the string and file input stream parameters, executes the statement, commits the transaction, and closes the stream and connection.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Store BLOB Data Into Database

This code connects to an Oracle database using JDBC, prepares an INSERT statement to add a record to a "pictures" table with a name, description, and image file, sets the parameter values, inserts the record into the database, and commits and closes the connection. It imports necessary Java classes, defines the database connection details, loads the Oracle driver, gets a connection, sets auto-commit to false, prepares the INSERT statement, sets the string and file input stream parameters, executes the statement, commits the transaction, and closes the stream and connection.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import import import import import

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

public class Main { static String url = "jdbc:oracle:thin:@localhost:1521:javaDemo"; static String username = "username"; static String password = "welcome"; public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, username, password); conn.setAutoCommit(false); String sql = "INSERT INTO pictures (name, description, image) VALUES (?, ?, ?)"; PreparedStatement stmt = conn.prepareStatement(sql); stmt.setString(1, "java.gif"); stmt.setString(2, "Java Official Logo"); File image = new File("D:\\a.gif"); FileInputStream fis = new FileInputStream(image); stmt.setBinaryStream(3, fis, (int) image.length()); stmt.execute(); conn.commit(); fis.close(); conn.close(); } }

You might also like