sql,java

sql,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 uploading like that.....

View Answers

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);
        }
    }
}

Ads









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,java
sql,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
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql  i am working on a project on deadlock in distributed transactions , and in that i am using my sql in java i need
JPA Tutorial
SQL. Java Persistence Criteria API provides to create typesafe queries...JPA Tutorial In this section we will discuss about the Java Persistence API... called Java Persistence API that facilitate developers to manage relational data
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 Training
Retrieving Values from a ResultSet SQL and Java Datatypes Creating...Advanced Java Training Advanced Java Programming Course for the Java beginners having some knowledge of Java programming Language. We are assuming
Learning Hibernate ORM - Free Training/Tutorial videos of Hibernate ORM with Java
and web categories, SQL, Java Database Connectivity (JDBC) and Relational Database... Java Training Institute offers comprehensive guidance on Hibernate, which... Object/Relational Mapping (ORM) or simply Hibernate tool, in Java programming
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

Ads