JAVA(JDBC)

JAVA(JDBC)

View Answers

August 12, 2008 at 10:38 AM

hai frnd.......
A simple method is just store the complete path of the image.
Hence the datatype will be varchar
Thanks anbd regards
prashu

August 12, 2008 at 11:52 AM

Hi friend,

package javacode;

import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.Blob;
import java.io.*;

class RetriveImage {
FileOutputStream image;
Connection con = null;
PreparedStatement pstmt = null;
Statement stmt= null;
ResultSet res = null;
StringBuffer query=null;
String filename = "javacode/rose.jpg";
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String userName = "amar";
String password = "amar123";

public RetriveImage(){
try{
query=new StringBuffer("insert into Image(id,imgName,image) values (?,?,?)");
File file= new File(filename);
Class.forName(driverName);
con = DriverManager.getConnection(url+dbName,userName,password);
stmt=con.createStatement();
pstmt=con.prepareStatement(query.toString());
pstmt.setInt(1, 6);
pstmt.setString(2,"rose");
pstmt.setBinaryStream(3, new FileInputStream(filename),(int)file.length());
pstmt.executeUpdate();
System.out.println("Successfully inserted into image .....");
ResultSet rs=stmt.executeQuery("select * from Image where image='image'");
if (rs.next()) {
Blob test=rs.getBlob("image");
InputStream x=test.getBinaryStream();
int size=x.available();
OutputStream out=new FileOutputStream("javacode/rose.jpg");
byte b[]= new byte[size];
x.read(b);
out.write(b);
}
}
catch(ClassNotFoundException cnfe){
System.out.println("ClassNotFoundException occured :"+cnfe);
}
catch(SQLException se){
System.out.println("SQLException occured :"+se);
}
catch(FileNotFoundException fe){
System.out.println("File Not Found Exception occured :"+fe);
}
catch(Exception e){
System.out.println("Exception occured :"+e);
}
finally{
try{
stmt.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
public static void main(String args[]) throws IOException{
RetriveImage ri = new RetriveImage();
}
}




August 12, 2008 at 11:53 AM

Read for more information.


http://www.roseindia.net/jdbc/save_image.shtml


Thanks.

Amardeep









Related Tutorials/Questions & Answers:
Java jdbc
Java jdbc  What is JDBC
Java JDBC
Java JDBC   Is the JDBC-ODBC Bridge multi-threaded
Advertisements
Java - JDBC
Java and JDBC programming  Need to learn the kills to develop the application using java and jdbc
Java JDBC
Java JDBC  What is the fastest type of JDBC driver
Java JDBC
Java JDBC  How to make pagination using JDBC
java servlets jdbc - JDBC
java servlets jdbc  i am running the servlet program with jdbc connections in this porgram i used two 'esultset' objects.. in this wat ever coding is available in the first resultset is executed like updating and retrieiving
java - JDBC
java  hello, i have oracle 8i,i am a java-learner, i would like to run a jdbc programs. please tell me the steps how to run the jdbc program  For the complete reference and tutorial on Java Database Connectivity visit
JAVA(JDBC) - JDBC
JAVA(JDBC)  Hello friends, please tel me, how can we retrieve..."; String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql... for more information. http://www.roseindia.net/jdbc/save_image.shtml
java - JDBC
have to use JDBC and oracle. plz send the details for connecting "java... sending data inserting code into database using JDBC with jsp... for database connectivity: http://www.roseindia.net/jdbc/jdbc-mysql
Java JDBC driver
Java JDBC driver  What is JDBC Driver
java - JDBC
java  how to get connectoin to database server from mysql through java programme  Hi Friend, Please visit the following link for more detailed information http://www.roseindia.net/jdbc/jdbc-mysql
Java JDBC
Java JDBC  Is JDBC-ODBC bridge multi-threaded?  NO. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls made.... The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls
Java jdbc class.forName error - JDBC
Java jdbc class.forName error  HI: how is possible that my JDBC connection to an MYSQL instance works inside the IDE (Netbeans) and not when I start it from the jar file? Could some please give some pointers please? Higly
java - JDBC
java  how can i connect jdbc with oracle 9i.please give detailed procedure.  Hi Friend, Use JDBC with Oracle Follow these steps: 1) Import the following packages in your java file:*********** import
java - JDBC
, The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge... is the traditional management layer of JDBC, working between the user
java jdbc
java jdbc  what is a prepared statement?   Hi Friend, It is a pre compiled form of Statement class. It send sql statements to the database... of its examples from the given link: JDBC Tutorials ThanksADS_TO_REPLACE_2
java - JDBC
metadata  Hi friend, 1. First import the java packages... = "com.mysql.jdbc.Driver"; 3.Creating a jdbc Connection String url = "jdbc.... Creating a jdbc Statement object Statement st = conn.createStatement(); 5
Java Jdbc connection
Java Jdbc connection  What are the two major components of JDBC
Java JDBC driver
Java JDBC driver  What are the different JDBC drivers available
Java Jdbc-odbc
Java Jdbc-odbc  What is the difference between JDBC and ODBC
Java JDBC ODBC
Java JDBC ODBC  What is the difference between JDBC and ODBC
JAVA - JDBC
JAVA  how to store and retrieve an image in a database(ORACLE)using java or JSP?  Hi friend, I am sending you image insert code in jsp using mysql jdbc driver so please change driver name and implement
Java Jdbc
Java Jdbc  sir i want to databse(oracle 10g)connectivity through java through program   Hi Friend, Follow these steps: 1) Import the following packages in your java file: import java.sql.*; import
java - JDBC
java   how insert the row through ResultSet using the insertRow()method   Hi Friend, Try the following code: import java.sql.... con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root
java - JDBC
automatically loaded. The driver is loaded by calling the Class.forName() method. JDBC... on JDBC visit to : http://www.roseindia.net/jdbc/understanding-driver-manager.shtml http://www.roseindia.net/jdbc/ Thanks
java - JDBC
available in that particular place in the same page.(by using Oracle and java(jdbc)).... please......It's very important and urgent....  Hi
java jdbc connecting probelm - JDBC
java jdbc connecting probelm  import javax.servlet.*; import javax.servlet.http.*; import javax.sql.*; import java.io.*; public class ECom...=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger
JDBC, JAVA
JDBC, JAVA  I want to develop a s/w that will work on a LAN, so is there any need for a server, bcoz I am using database to store information, and these information will be on LAN
java - JDBC
java  how to access excel file through jdbc show record in table.... Click "Ok" and restart your compiler. 7. Compile the following java code...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=DriverManager.getConnection("jdbc:odbc:excel
java - JDBC
java  how to create a database for java with images in ms access(2007...{ String url="jdbc:odbc:access"; File file=new File("c:\\barbie.jpg...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc
JAVA - JDBC
JAVA  WRITE A PROGRAM USING SERVLET AND JDBC FOR DEVELOPING AN ONLINE APPLICATION FOR THE SHOPPING OF COMPUTER SCIENCE BOOK.YOU HAVE TO CREATE... the following links to have sample Servlet and JDBC applications. http
java - JDBC
java  How to connect java(jsp) and oracle8i? plz, explain every step included in the process. It's urgent..  Hi friend, Code to help... oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc
JAVA - JDBC
JAVA  HOW TO CONNECT JDBC IN SERVLET AND HOW TO PREPARE WEB.XML   Hi Friend, Please visit the following links: http://www.roseindia.net/servlets/ServletInsertingData.shtml http://www.roseindia.net/servlets
java - JDBC
java  How to do connectivity with JDBC on a simple frame ?  Hi friend, Insert into database Insert User Information page User ID
Java Jdbc connection
Java Jdbc connection  What is the use of Class.forName
java - JDBC
java  what is the life of a resultset object  Hi friend, In the JDBC 2.0 core API, the ResultSet interface has a set of new updateXXX..."); ---------------------------------------------- Read for more information. http://www.roseindia.net/jdbc
jdbc java
jdbc java  i have one table in database, now i want to store in notepad these table field, how is it possible through jdbc?   Hi Friend... = DriverManager.getConnection( "jdbc:mysql://localhost:3306/register", "root
java - JDBC
java  java code for retrive an image from mysyl database through jFrame  Hi Friend, Try the following code: import java.sql.... con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root
java - JDBC
java  please help to retrieve image from database when a search query is given from a text box in java code using oracle as a backend database ...").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql
java - JDBC
"; public static final String DB_URL="jdbc:mysql://localhost:3306/link_db... visit to : http://www.roseindia.net/java/beginners/SingletonPattern.shtml
java - JDBC
java  how to store and retrive images from oracle 10g using jdbc..."; String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql...(); } } ---------------------------------------------------- in this program using jdbc driver, if you
java - JDBC
java  java code for retrive images from mysql database through jFrame  Hi Friend, Try the following code: import java.sql.*; import...("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc
java - JDBC
  Hi Read for more information. http://www.roseindia.net/jdbc... url = "jdbc:mysql://localhost:3306/"; String dbName = "databasename
java - JDBC
; String url = "jdbc:mysql://192.168.10.211:3306/"; String db = "amar... -------------------------------------- Read for more information. http://www.roseindia.net/java/example/java/awt/ Thanks. Amardeep
Java jdbc connection
Java jdbc connection  Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection
java - JDBC
= DriverManager.getConnection( "jdbc:mysql://localhost:3306/test", "root", "root
java - JDBC
conn = DriverManager.getConnection("jdbc:oracle:thin:@training:1521:Oracle
java - JDBC
= DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st
java - JDBC
= "jdbc:mysql://localhost:3306/"; String dbName = "register"
java - JDBC
("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con1; con1=DriverManager.getConnection("jdbc...=DriverManager.getConnection("jdbc:odbc:Mycon","",""); PreparedStatement stat2

Ads