
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.....

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);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.