Share on Google+Share on Google+

Sireesha
sql,java
1 Answer(s)      6 years 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.....

Ads

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
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
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
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads