How to insert a data&time to Database date field
Dear Friends,
I have created a Stored Procedure which takes a Date data type as an input,When i call this procedure from java i need to set the data&time in
yyyymmddhhmmss format. How to set this from java ?.
Rgds
Mohan S
How to set this from java ?.Usually you use a prepared statement and one of the set methods.
Or you can use setString() and format the date yourself using SimpleDateFormat.
Similar Messages
-
How to insert/update Date field in Oracle with java code
Dear All
I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.
By using these 3 lines i am able to insert/update only date.
java.util.Date date = new java.util.Date();
long dateLong = date.getTime();
stmtPrep.setDate(33, new java.sql.Date(dateLong));
Below code retrives the date exactly what i need but unable to pass in the statement:
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a");
java.util.Date d = (Date) new java.util.Date();
String stringdate = formatter.format(d);
String tmpdate = dateFormat();
stmtPrep.setString(33, tmpdate); -- I tried with setObject as well but same error coming.
Error is:
ORA-01830: date format picture ends before converting entire input string
Can u guide me how to get full date time with AM/PM?sasikrishna wrote:
Dear All
I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.
By using these 3 lines i am able to insert/update only date.
java.util.Date date = new java.util.Date();
long dateLong = date.getTime();
stmtPrep.setDate(33, new java.sql.Date(dateLong));That's by design. A java.sql.Date object matches an SQL DATE column (which doesn't include a time component). If you want something which matches an SQL TIMESTAMP colum (which includes both date and time components) then you should use a java.sql.Timestamp object. -
How to insert the data from XML to a table
Hi,
I'm using Oracle 10g Express Edition
I need help in How to insert the data from XML file into the table.
Below is the example i'm working on..
I have create ridb user with below mentioned privileges:
Account Status Locked Unlocked
Default Tablespace: USERS
Temporary Tablespace: TEMP
User Privileges :
Roles:
CONNECT
RESOURCE
Direct Grant System Privileges:
CREATE DATABASE LINK
CREATE MATERIALIZED VIEW
CREATE PROCEDURE
CREATE PUBLIC SYNONYM
CREATE ROLE
CREATE SEQUENCE
CREATE SYNONYM
CREATE TABLE
CREATE TRIGGER
CREATE TYPE
CREATE VIEW
& table is created TRIALZIPCODES below mentioned is the DDL:
CREATE TABLE TRIALZIPCODES
STATE_ABBR VARCHAR2(20) NOT NULL
, ZIP_CODE NUMBER(10, 0) NOT NULL
, ZIP_CODE_EXT VARCHAR2(20)
Below is the XML FILE: which is stored in C:\OracleProject Folder
File name: trial.xml
<?xml version="1.0" ?>
<metadata>
- <Zipcodes>
- <mappings Record="4">
<STATE_ABBREVIATION>CA</STATE_ABBREVIATION>
<ZIPCODE>94301</ZIPCODE>
</mappings>
- <mappings Record="5">
<STATE_ABBREVIATION>CO</STATE_ABBREVIATION>
<ZIPCODE>80323</ZIPCODE>
<ZIP_CODE_EXTN>9277</ZIP_CODE_EXTN>
</mappings>
</Zipcodes>
</metadata>
PL/SQL Procedure:which i'm trying to execute from SQLDeveloper
create or replace
PROCEDURE TRIAL AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
begin
-- DBMS_XMLGEN.setRowTag ( ctx IN ctxHandle, rowTag IN VARCHAR2);
-- DBMS_XMLGEN.setRowSetTag ( ctx IN ctxHandle, rowSetTag IN VARCHAR2);
-- the name of the table as specified in our DTD
DBMS_XMLGEN.SETROWSETTAG(l_context_handle,'zipcodes');
-- the name of the data set as specified in our DTD
DBMS_xmlgen.setRowTag(l_context_handle,'mappings');
-- for getting the output on the screen
dbms_output.enable(1000000);
-- open the XML document in read only mode
v_FileHandle := utl_file.fopen('c:/OracleProject','trial.xml', 'r');
loop
BEGIN
utl_file.get_line(v_FileHandle, charString);
exception
when no_data_found then
utl_file.fclose(v_FileHandle);
exit;
END;
dbms_output.put_line(charString);
if finalStr is not null then
finalStr := finalStr || charString;
else
finalStr := charString;
end if;
end loop;
-- for inserting the XML data into the table
insCtx := DBMS_XMLSTORE.NEWCONTEXT('RIDB.TRIALZIPCODES');
insCtx := DBMS_XMLSTORE.INSERTXML(insCtx, finalStr);
dbms_output.put_line('INSERT DONE '||TO_CHAR(rowsp));
DBMS_XMLStore.closeContext(insCtx);
END;
END TRIAL;
For the first time when i complied i got the errors as :
Procedure RIDB.PROCEDURE1@RIDB
Error(16,14): PLS-00201: identifier 'UTL_FILE' must be declared
Error(16,14): PL/SQL: Item ignored
Error(29,1): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(29,1): PL/SQL: Statement ignored
Error(33,1): PL/SQL: Statement ignored
Error(33,19): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(36,1): PL/SQL: Statement ignored
Error(36,17): PLS-00320: the declaration of the type of this expression is incomplete or malformed
So i logged in as sys & grant the permission to execute on UTL_FILE to ridb (user):
SQL Statement:
grant execute on utl_file to ridb
So, it got compiled successfully but when i execute it gives me error as:
Source does not have a runnable target.
What does this mean?
So I browse through forum & i got to know that i need to initial the UTL_FILE_DIR ="C:/OracleProject" in init.ora
So can i edit the init.ora with notepad.When i tried to do that it says permission denied
In my system it shows the init.ora file in path C:\oraclexe\app\oracle\product\10.2.0\server\config\scripts
but there is also other file initXETemp in the same path do i need to do the changes in it.
I have tried even editing the SPFILE as mentioned below:
C:\oraclexe\app\oracle\product\10.2.0\server\dbs\SPFILEEXE - I had edit this file using notepad & set the value of UTL_FILE_DIR ="C:/OracleProject". So next time when i restarted i'm unable to log on to the database.
So i had reinstall the software again.
Could you please let me know how to proceed..hi,
I have created the directory from sys database
CREATE or replace DIRECTORY XML_DIR2 AS 'C:\OracleProject';
& grant read,write access to the user
grant read,write on directory XML_DIR2 to RIDB;
& i had change the tag name in the xml file as shown below:
<?xml version = '1.0'?>
<metadata>
<Zipcodes>
<mappings Record="4">
<STABBRE>CA</STABBRE>
<ZIPCODE>94301</ZIPCODE>
</mappings>
<mappings Record="5">
<STABBRE>CO</STABBRE>
<ZIPCODE>80323</ZIPCODE>
<ZIPCODEEXT>9277</ZIPCODEEXT>
</mappings>
</Zipcodes>
</metadata>
TRIALZIPCODE table as shown below:
CREATE TABLE "RIDB"."TRIALZIPCODE"
( "STABBRE" VARCHAR2(20 BYTE),
"ZIPCODE" NUMBER(*,6) NOT NULL ENABLE,
"ZIPCODEEXT" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
I have tried two methods as shown below:
Procedure 1:
create or replace
PROCEDURE TRIAL_V2 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
insCtx := DBMS_XMLStore.newContext('DEV.TRIALZIPCODES');
DBMS_XMLStore.setUpdateColumn(insCtx, 'STABBRE');
DBMS_XMLStore.setUpdateColumn(insCtx, 'ZIPCODE');
DBMS_XMLStore.setUpdatecolumn(insCtx, 'ZIPCODEEXT');
DBMS_XMLStore.setRowTag(insCtx, 'mappings');
cnt := DBMS_XMLStore.insertXML(insCtx, xmldoc);
DBMS_XMLStore.closeContext(insCtx);
END;
Procedure 1 was compiled with out errors but when i execute i got the error as :
Source does not have a runnable target.
Procedure 2_
CREATE OR REPLACE PROCEDURE TRIAL_V3 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
INSERT INTO trialzipcode (STABBRE, ZIPCODE, ZIPCODEEXT)
SELECT extractvalue(x.column_value, 'mappings/STABBRE'),
extractvalue(x.column_value, 'mappings/ZIPCODE'),
extractvalue(x.column_value, 'mappings/ZIPCODEEXT')
FROM TABLE(
XMLSequence(
EXTRACT(
xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') ),
'metadata/Zipcodes/mappings'
) x
END;
END TRIAL_V3;
Procedure 2 was complied without errors but when i execute i got the error as:
Connecting to the database RIDB.
ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the file specified.
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "SYS.XMLTYPE", line 287
ORA-06512: at "RIDB.TRIAL_V3", line 12
ORA-06512: at line 2
Process exited.
Disconnecting from the database RIDB.
Could you please let me know how to proceed... -
SQL Loader-How to insert -ve & date values from flat text file into coloumn
Question: How to insert -ve & date values from flat text file into coloumns in a table.
Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
How to load such values in columns of database using SQL Loader?
Please guide.Question: How to insert -ve & date values from flat text file into coloumns in a table.
Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
How to load such values in columns of database using SQL Loader?
Please guide. Try something like
someDate DATE 'DDMMYYYY'
someNumber1 "TO_NUMBER ('s99999999.00')"
someNumber2 "TO_NUMBER ('99999999.00s')"Good luck,
Eric Kamradt -
If Both tables having References then how to insert the data each other
Hai EveryOne..,
My Sample data.,
Create table emp (empno number primary key,ename varchar2(20));
Create table emp_dup (empno number references emp(empno),ename varchar2(20) primary key);
alter table emp add constraint ename_fk foreign key(ename) references emp(ename);
My Question is How to insert the data into these two tables?
Its a *"Circular Reference"* Concept.
Please ...
Thank You!!You need to set the DEFERRED clause of the constraint when you create your foreign key as DEFERRABLE by which you can move the constraint validation at transaction level.
In an interview point of view that could be a reasonable answer. But in real time this could be strongly questionable.
Here is an example
SQL> create table emp1 (empno number, ename varchar2(10))
2 /
Table created.
SQL> create table emp2 (empno number, ename varchar2(10))
2 /
Table created. Define Primary Key for two tables
SQL> alter table emp1 add constraint emp1_pk primary key (empno)
2 /
Table altered.
SQL> alter table emp2 add constraint emp2_pk primary key (ename)
2 /
Table altered. Add foreign key for two tables with DEFERRED clause set as DEFERRABLE
SQL> alter table emp1 add constraint emp1_fk foreign key (ename) references emp2(ename) initially deferred deferrable
2 /
Table altered.
SQL> alter table emp2 add constraint emp2_fk foreign key (empno) references emp1(empno) initially deferred deferrable
2 /
Table altered. Now here is the test case
SQL> insert into emp1 values (1, 'karthick')
2 /
1 row created.
SQL> commit
2 /
commit
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (ARBORU.EMP1_FK) violated - parent key not found So the validation is done at Transaction level. Now let insert the value into both tables.
SQL> insert into emp1 values (1, 'karthick')
2 /
1 row created.
SQL> insert into emp2 values (1, 'karthick')
2 /
1 row created.
SQL> commit
2 /
Commit complete. -
How do i insert a drop down calender to insert the date field.
How do i insert a drop down calender to insert the date field i my create a form
Hi,
You can use the date object FormsCentral provides. When you test the form in browser, the date field will show a pulldown calendar when clicked upon.
Thanks,
Wenlan -
How to Insert a record in a database table in debugging mode in production
Hi,
How to Insert a record in a database table in debugging mode in production ?
Waiting for kind response.
Best Regards,
Padhy
Moderator Message : Duplicate post locked.
Moderator message : Warning. Don't create multiple threads for same question.
Edited by: Vinod Kumar on May 12, 2011 11:02 AM
Edited by: Vinod Kumar on May 12, 2011 11:04 AMHi Senthil,
Regards,
Phani Raj Kallur
Message was edited by: Phani Raj Kallur -
How to insert Legacy data into QP_RLTD_MODIFIERS table?
How to insert Legacy data into QP_RLTD_MODIFIERS table in R12 instance.
I would use the API QP_Modifiers_PUB.Process_Modifiers for pushing legacy pricing data into R12. QP_RLTD_MODIFIERS is only used for certain types of discounts (in my prod environnment, only promos have data in this table).
-
How to insert the data using matrix
Hi
All how to insert the data using matrix feild
plz help me
thanks
LoyHi Loy,
The best way to fill an entire matrix is to use a DBDatasource, here is some sample code:
Dim oForm As SAPbouiCOM.Form
oForm = SBO_App.Forms.Item("YourFormTypeID")
'1. Add a DBDataSource to the form
oForm.DataSources.DBDataSources.Add("OUSR")
Dim oColumnDBS As SAPbouiCOM.Column
Dim oColumnUDS As SAPbouiCOM.Column
Dim i As Integer
Dim GenEdt As SAPbouiCOM.EditText
Dim oMatrix As SAPbouiCOM.Matrix
Dim oColumns As SAPbouiCOM.Columns
Dim oDBDataSource As SAPbouiCOM.DBDataSource
oMatrix = oForm.Items.Item("7").Specific
oColumns = oMatrix.Columns
'2. DBDataSource: Binding a field / alias of the table to a column
oColumnDBS = oColumns.Item("V_1")
oColumnDBS.DataBind.SetBound(True, "OUSR", "U_NAME")
'3. getting the data sources bound to the form
oDBDataSource = oForm.DataSources.DBDataSources.Item("OUSR")
oMatrix.Clear()
' Querying the DB Data source
oDBDataSource.Query()
' Adding the data to the matrix
oMatrix.LoadFromDataSource()
When you want to fill a specific field use :
GenEdt = oMatrix.Columns.Item("V_2").Cells.Item(1).Specific
GenEdt.String = "Hello" -
Hello.
How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)
I have text field which has a databind to a date field. When I click on it, we can select the date, it is added on the format (dd,mm,yyyy). When I want to insert this date field to a database It doesnu2019t allow me to do it because it will only accept date field on the format (mm,dd,yyyy)
I tried to store this format on a date variable and I get a message saying that is impossible to convert a string into a date.
Regards,
JoseHi Jose,
usually you format strings in c# like
string.Format("{0:yyyyMMdd}", insertyourstring);
in your case
string.Format("{0:MM/dd/yyyy}", insertyourstring);
[look here|http://idunno.org/archive/2004/14/01/122.aspx]
there are more details
if everything fails split the string with Mid()
or ask me
lg David -
I am working in Adobe Acrobat 9 Pro and just created a pdf form from a MS Word document. I need to find out how to have a date field in my form which will update automatically.
Update automatically under which circumstances, exactly?
-
How to add the date field in the dso and info cube
Hi all.
I am new to bi 7. in the earlier version v hav to button to add the date field. but in the bi 7 der is no option so can any body tell me how to add the date field in the data targets
Thanks & Regard
KKmy prob is solved
KK -
How to insert a HYPERLINK in a template Editable Field?
Question: How to insert a HYPERLINK in a template Editable Field?
Hi
Does anyone know how to insert a HYPERLINK in a template Editable Field?
I want the link to always display the word "Cities".
But the URL will change with each child page.
Here's what I've got so far . . .
<!-- TemplateBeginEditable name="Cities" -->Cities<!-- TemplateEndEditable -->
Thanks so much!NOTE: This is to go into the TEMPLATE
Your best bet is to keep the hyperlink OUT of the editable Field and to make the HREF attribute of the link editable.
This would go in the head of your document:
<!-- TemplateParam name="href" type="URL" value="" -->
This would go where you want the link to appear:
<a href="@@(href)@@">cities</a>
THE BETTER WAY: You can either paste these quotes into the appropriate places in your template or you can insert:
<a href="#">cities</a>
and click inside the opening <a> tag.
Then go to Modify > Templates > Make Attribute Editable
In the dialog box "Editable Tag Attributes" you should now see "Choose which attributes of this A tag should be editable."
If HREF is not showing in the drop-down, do Add and put it there.
Check the box to Make this attribute editable.
Give a name for this editable attribute (if you have more than one on a page, you will want it to be understandable, like "cities" for your cities links).
Make sure it is of Type URL
If you want a default URL in place, put one in the Default field.
Then push OK.
To use it, on each page, do Modify > Template Properties... choose the property to edit, and put the new URL in the entry field.
Press OK.
Beth -
How to set the data fields column wide at sqlplus
Dear Sir/Madam
I would like to know how to set the data fields column wide at sqlplus
Thanks
Francissee
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch6.htm#sthref1131
and the FORMAT clause of the COLUMN command in
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12013.htm#BACHCABF -
How to insert sign date "now()" in database ?????
I am a newbie. Using DW CS5 I have been able to get a number of web pages on my web site to work well. My problem is with my “sign in form”. I want to add in the sign in form a hidden field for the date that the user signs up.
But the signup_date value in the database is not been entered. I do have a “work around”. If I replace the last “%s” in the $insertSQL statement with NOW(), the correct signup_date is entered in the database table “users”. However, I want to learn to do it “right”. My questions:
1. What is the “best” way to accomplish my desire results?
2. What do the “%s” stand for in the $insertSQL statement? I think it is an array, but I do not understand this line of code that DW generated. Can you explain is plain English?
Below is the important part of the code (I hope I sent enough to explain the problem) for the sign form: (disregard the /////// they are only there to indicate different sections of the code).
//This is the code from the input form for the hidden field "signup_date"
</tr>
<tr>
<td align="left" valign="top"><input name="signup_date" type="hidden" id="signup_date" value="NOW()" />
<td><input type="submit" name="Submit" value="Join Now!"></td>
</tr>
</table>
//This is the dreamweaver code to insert the date into the data base:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frJoin")) {
$insertSQL = sprintf("INSERT INTO users (first_name, last_name, email_address, username, info, user_level, signup_date) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['first_name'], "text"),
GetSQLValueString($_POST['last_name'], "text"),
GetSQLValueString($_POST['email_address'], "text"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['info'], "text"),
GetSQLValueString($_POST['user_level'], "text"),
GetSQLValueString($_POST['signup_date'], "date"));
Thanks !!I do have a “work around”. If I replace the last “%s” in the $insertSQL statement with NOW(), the correct signup_date is entered in the database table “users”. However, I want to learn to do it “right”.
Your "workaround" is actually the correct method. The way that you think is "right", by entering the date into a hidden field, is actually the wrong way. Hidden fields can be manipulated. Inserting data directly into the query is the desired method, like the method you are currently using. It's not a "workaround", it's the correct method. You hidden field is not working because you have not told the page that the NOW() in the hidden field should be processed through php. NOW() is MySQL function. Use php to echo current date in hidden field if you want to use the "wrong" method of processing the date into your query.
<td align="left" valign="top"><input name="signup_date" type="hidden" id="signup_date" value="<?php echo date("Y-m-d H:i:s"); ?>" /> -
How to insert multiple data to non database data block?
Hi all,
I'm new in using form builder. I have a question about insert multiple data to non database data block.
I want to upload a csv file that content the attendance transaction of all of employees. If the employee in that
file doesn't exist in that company,so I must record the employee number into non database data block.
If I just upload one employee data, I can record it to that data block. But, if more than one, it didn't works.
May you help me?
Thanks..
Tikayou might need a NEXT_RECORD or CREATE_RECORD to go to the next reord in that block. It would be easier to help if we knew your code.
Maybe you are looking for
-
SharePoint 2013 Blog Site not showing current navigation(Left Navigation)
I have created a blog site but blog pages are not showing my current navigation, it has got its own left navigation, Can i show left (current) navigation? I am trying to find the page layout being used for blog items but unable to find.
-
Anyone got experience with Filemaker and Mac OSX v10.4 on a G5
I am in the transition period from PPC to Intel, and installation of Aperture. My main box is an Apple G5 DP running OSX 10.3.9 and I have the upgrade software to go to OS 10.4+ but have not yet installed it. I also have a recent Intel MacBook Pro ru
-
Cash Register Program (processing "sales" and "amounts" )
I'm having trouble adding amounts to an array of capacity that the user sets at the beginning of the program. It seems very easy, but I just don't know what to do. It is for a school assignment, so I'm not asking for any freebies. I'd just like to be
-
HT201401 My volume down button has stopped working. Help
Need some help troubleshooting
-
Hey I bought my MacBook Pro a couple days ago, but I bought OS X Lion for $30 without knowing that there was a free upgrade available... Do you think that if I apply for the FREE upgrade, they will put the $30 back onto my iTunes account?...