i am writing some code in java.that values are stored in database.plz send me one example for this for example taking the fields as s.no,category,name of the candidate,age,title of the project,video uploading,photo uploading like that.....
April 20, 2011 at 4:24 PM
We have created a table in database named 'project'.
CREATE TABLE `project` (
`sno` int(255) NOT NULL auto_increment,
`category` varchar(255) default NULL,
`name` varchar(255) default NULL,
`age` int(255) default NULL,
`title` varchar(255) default NULL,
`video` longblob,
`photo` longblob,
PRIMARY KEY (`sno`)
);
Here is the java code:
import java.io.*;
import java.sql.*;
class InsertData{
public static void main(String[] args){
try{
File f1=new File("C:/video.wav");
File f2=new File("C:/rose.jpg");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
PreparedStatement ps = con.prepareStatement("insert into project(category,name,age,title,video,photo) values(?,?,?,?,?,?)");
ps.setString(1,"Software");
ps.setString(2,"roseinida");
ps.setInt(3,10);
ps.setString(4,"Shopping Cart");
FileInputStream fis1 = new FileInputStream(f1);
ps.setBinaryStream(5, (InputStream)fis1, (int)(f1.length()));
FileInputStream fis2 = new FileInputStream(f2);
ps.setBinaryStream(6, (InputStream)fis2, (int)(f2.length()));
ps.executeUpdate();
System.out.println("Inserted successfully!");
}
catch(Exception e){
System.out.println(e);
}
}
}
Related Tutorials/Questions & Answers:
What should I learn first SQL or Java?What should I learn first
SQL or
Java? Hi,
I am total beginner... in programming particularly
Java.
What should I learn first
SQL or
Java?
Thanks
... and after that you can learn
SQL.
Learning
Java first is important its the base
sql,javasql,java i am writing some code in java.that values are stored in database.plz send me one example for this for example taking the fields as s.no,category,name of the candidate,age,title of the project,video uploading,photo
Advertisements
file in java - Java Beginnersfile in java I want to count the number of white line and comment line in a file (.
sql) with
java
if you have an example
thank you in advance
Connectivity with sql in detail - JDBCConnectivity with
sql in detail Sir/Madam,
I am unable to connect the
sql with
Java. Please tell me in detail that how to connect.
Thankyou. Hi Friend,
Put mysql-connector
JPA Tutorial the
Java objects to the relational database table. Like
SQL JPA has has...
SQL.
Java
Persistence Criteria API provides to create typesafe queries...JPA Tutorial
In this section we will discuss about the
Java Persistence API
HibernateBooks and typographical spaghetti needed to put their
SQL into a
Java program... extension (HQL), as well as in native
SQL, or with
Java-based Criteria... that more thoroughly isolate your Spring app from
SQL.
Java Data Objects
Advanced Java Tutorials a Statement
Retrieving Values from a ResultSet
SQL and
Java... Advanced
Java Tutorials
...;
In this section you will find the
Java topics that should be part of Advanced
Java
study
Advanced Java Training a Statement
Retrieving Values from a ResultSet
SQL and
Java Datatypes...Advanced
Java Training
Advanced
Java Programming Course for the
Java beginners having some
knowledge of
Java programming Language. We are assuming
What is Persistence Framework? on writing
Java classes, and not worrying about maintenance of matching
SQL... technology from
Java without needing to know
SQL or be an expert in relational... simplifies the
development process.
Open Source Persistence Framework in
Java Beginners Stuts tutorial. introduces
SQL in
java code
while CMP & JDO adopt declarative management... by Sun. And the
recently introduced JSF (
Java Server Faces) also...
Architect for Sun's
Java Web Services Development Pack (JWSDP
Complete Hibernate 3.0 and Hibernate 4 Tutorial. Hibernate also allows
you to express queries using native
SQL or
Java-based... mapping tool for
Java platform. It
provides powerful, ultra-high performance object/relational persistence and
query service for
Java. Hibernate lets you