Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC sql,java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sireesha
sql,java
1 Answer(s)      3 years and 8 months ago
Posted in : JDBC


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


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


Related Tutorials/Questions & Answers:
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
browse a file with java - Development process
browse a file with java  I want to count the number of white line and comment line in a file type with sql with java
Connectivity with sql in detail - JDBC
Connectivity 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
Connectivity with sql in detail - JDBC
Connectivity 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
file in java - Java Beginners
file 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
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
Connectivity with sql in detail - JDBC
Connectivity 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
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
Advanced Java Tutorials
Values from a ResultSet SQL and Java Datatypes Creating... Advanced Java Tutorials     ...; In this section you will find the Java topics that should be part of Advanced Java study
Beginners Stuts tutorial.
shortly ,is said to favor JDO strongly.(BMP introduces SQL in java code while CMP.... And the recently introduced JSF (Java Server Faces) also is the contribution of Craig...'s Java Web Services Development Pack (JWSDP). That is sufficient enough list
What is Persistence Framework?
on writing Java classes, and not worrying about maintenance of matching SQL... Java without needing to know SQL or be an expert in relational database design... simplifies the development process. Open Source Persistence Framework in Java
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
JDBC (Java Database Connectivity) -Tutorials
for writing embedded SQL in Java applications that a preprocessor can read... JDBC (Java Database Connectivity) -Tutorials    Introduction to JDBC Java started
 

 

 

DMCA.com