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



Home Answers Viewqa JSP-Servlet date example with database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


himanshu kakkar
date example with database
2 Answer(s)      2 years and 6 months ago
Posted in : JSP-Servlet


i want to insert date in database(oracle) through jsp. thanx in advance...


Advertisement
View Answers

March 5, 2012 at 4:08 PM


<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<%
Connection con=null;
PreparedStatement pstatement = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "file_upload";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url+dbName,userName,password);
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);


String strDateNew = sdf.format(now) ;




String queryString = "INSERT INTO file_tbl set file_date='"+strDateNew+"'";

//out.println(queryString);

pstatement=con.prepareStatement(queryString);


val = pstatement.executeUpdate();

if(val>0)
{
%>
<br><br>
<b><%=strDateNew%> Inserted into Database .</b>
<%
}


}
catch(Exception e)
{}
}
%>
</html>


March 5, 2012 at 4:09 PM


<%@page import=" java.sql.*, java.util.*"%>
<%
try{
Connection conn=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
conn = DriverManager.getConnection("jdbc:odbc:access");

String INSERT_RECORD = "insert into insertDate(id,myDate) values(?, ?)";

PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD);
pstmt.setString(1, "1");
java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
pstmt.setDate(2, sqlDate);
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>


Related Tutorials/Questions & Answers:
date example with database
date example with database  i want to insert date in database(oracle) through jsp. thanx in advance
insert date into database using jsf
insert date into database using jsf  Hello I need a simple example of source code to insert a date into a database using jsf what do I have to put in backing bean and page jsf ( i need juste a date ) thanks
Advertisements
Hibernate criteria date Example
Hibernate criteria date Example  Example of Hibernate criteria date. Check the tutorial hibernate criteria date. Check the Latest tutorials, articles and examples of Hibernate Framework. Thanks
Hibernate criteria for date. Example
Hibernate criteria for date. Example  What to use the Hibernate criteria for date in Hibernate based application? I want example of Hibernate criteria for date in Hibernate orm. Thanks   Example of Hibernate criteria
display date to jsp from database
display date to jsp from database   display date to jsp from database to calender if the start date and end date is available than calender date... not available in database field than show in green color and clickable. NOTE :- Date
Hibernate criteria date between Example
Hibernate criteria date between Example  Hibernate criteria date between Example I want example of hibernate criteria date between with source code. Share me the url. Thanks   Example of Hibernate criteria date
Hibernate Criteria Max Date Example
Hibernate Criteria Max Date Example   How to write example program... the following links: Example: Hibernate Criteria Max Date. Check the tutorial... for finding max Date in Java program then check the following links: Example
Insert current date into MYSQL database
Insert current date into MYSQL database In this tutorial, you will learn how to insert current date into database. In most of the applications, there is a need to insert date or time to database. Mysql provides several datatypes
Inser date in database - Development process
Inser date in database  Hi, In the follwing code i want to store system date in to database.First column as date field and Service_No ,UserName,CabinetSerialNo, ......... Thanks Prakash insert.jsp
Retrieve date from MYSQL database
Retrieve date from MYSQL database In this tutorial, you will learn how to retrieve date from database. Storing and Retrieving dates from the database.... The default format of date in MYSQL is YYYY-MM-DD. Example import java.sql.
Simple Date example
Simple Date example       In this section we have presented a simple Date example that shows how you can use different constructors of Date. We can construct the Date
Jsp Code to store date in database - JSP-Servlet
Jsp Code to store date in database   Hi, Can u give me jsp code to store current date in to database. Thanks Prakash
Mysql Date Select
; The Tutorial elaborate an example from 'Mysql Date Select'. This section makes you easy to understand how to get the current date from your database... your database as fieldname 'DATE'. Query to select date  SELECT DATE
Formatting Date for a Locale Example
Formatting Date for a Locale Example       This example shows how to format Date using SimpleDateFormat class. In this program we are format date for different
Retrieve Date Time Frm Database - Development process
Retrieve Date Time Frm Database  Hi Friend, Ow to retrieve Date and Time at a time from ms Access database. For Storing data time... is inserted into the database"); statement.close(); connection.close
struts2.2.1 date Format example
struts2.2.1 date Format example. In this example, We will discuss about the different type of date format using struts2.2.1. Directory structure of example.  1- index.jsp   <html> <head> <title>Date
Date Tool Example
Date Tool Example       This Example shows you how to display date and time velocity. ... and properties. Date date = cal.getTime(): Here we created Date
Simple Date Format Example
Following is a simple date format example made using Format class. We have uses a pattern of special characters to date and time format. In this example... is a simple Date Format Example: import java.text.*; import java.util.*; public
Date Field Midlet Example
Date Field MIDlet Example       This example illustrates how to insert date field in your form. We... static variable DATE which is 0. We are taking both DateField variable
Date Example
Date Example       In this section we are discussing about the specific date using the Date class object, retrieving milliseconds from the Date object, elapsed time, date
Get date data type from table
GET DATE DATA TYPE FROM TABLE In this example , we will get "Date" data type from a table of "Mysql" database and it also display...);             }         Date date = new Date();         System.out.println("Today's
JSP Database Example
This example shows you how to develop JSP that connects to the database and retrieves the data from database. The retrieved data is displayed on the browser. Read Example JSP Database Example Thanks
Import Excel file(date) into mysql database in php
Import Excel file(date) into mysql database in php  I try to import excel file which contains data date(yyyy-mm-dd) into mysql database in php...(); //connect to the database $connect = mysql_connect("localhost","root",""); mysql
Date Format Example
Date Format Example       This example shows how to format Date using Format class. In this program we use a pattern of special characters to date and time format
Parsing Date Example
Parsing Date Example       This example shows how to parsing date using Format class... and parsing dates. It allows for formatting date into text , parsing text into date
Code to insert date in to database - Development process
Code to insert date in to database  Hi , in my following code i want to store date in to msaccess database. i have tried many queries, but am getting error . plz send me code Error 500--Internal Server Error
get data between date from msaccess database
get data between date from msaccess database  here is my code, i want to get data between date using jsp with msaccess.i stored date into database in string.when i got output it displayed before month data
JSP date example
JSP date example      ...; The heart of this example is Date() function of the java.util... the current date and time. So the following code accomplish
Simple date formatter example
Simple date formatter example       In this section of simple date formatter example we... class to convert the date into the specified format. There are various constructors
store current system date in to database - Development process
store current system date in to database  Hi,this is my code . here iwant to store current system date in to database and want to store subdept..."].elements["combo2"].options.length=0; for (var i=0;i<% java.util.Date date
Parsing Date And Time Example
Parsing Date And Time Example       This example shows how to parsing date and time using Format... for formatting and parsing dates. It allows for formatting date into text , parsing
Advertisements
 

 

 

DMCA.com