Converting a character string to into a date raise ORA-01843
I always confused in using to_date() function,such as the following example.How could I convert the string "'8-十月-2006 " into a date correctly.Thank you in advance.
SQL> select TO_DATE('18-十月-2006 16:49:57','dd-mon-yyyy hh24:mi:ss','nls_DATE_language=''SIMPLIFIED CHINESE''') from dual;
select TO_DATE('18-十月-2006 16:49:57','dd-mon-yyyy hh24:mi:ss','nls_DATE_language=''SIMPLIFIED CHINESE''') from dual
ORA-01843: not a valid month
Hello:
I suppose you have a bad Oracle-client enviroment. If you note, you can't see a valid month, in place you are seeeing tho characters: '??'. This often indicates that you Oracle client settings (like NLS_LANG, NLS_DATE, etc.) are bad and you are not cappable to do some translation to see it.
Try if you can see another data from your database in Chinesse format, because also is possible that enviroment of your Oracle server is badly configured (like lang variables).
Similar Messages
-
Date error ORA-01843: not a valid month
Hi,
I am in a 4.01 Apex environment with NLS_DATE_FORMAT mm/dd/yyyy. I created a view with a CASE statements using 'when eventstartdate between '08/15/2010' and '06/1/2011' then...' clauses and the view is created fine. I also can query the view with no problem with SQL workshop and the CASE statements work as expected. When I create an interactive report on that view I keep getting ORA-01843: not a valid month. I even tried matching the format in the Interactive Report column format mask to the NLS format for the date and still get error.
What seems especially strange to me is that even if I have the view column defined with a 'to_char' I still get the same error when I use the CASE statement to build the view. Doesn't the Interactive Report just 'see' the View column definitions-- why should it 'care' how the view was built?
The only way I can get the View to work with an Interactive report in any manner is to remove all the CASE statements and define the 'eventstartdate' as text using to_char but that then eliminates my ability to do any filters that require date comparisons with between or '>', '<'.
Help would be appreciated!
Thanks,
PatQuick late night response - always convert your dates for comparison. Apples to apples
Instead of between '01/31/2012', use either
TO_DATE('01/31/2012', 'MM/DD/YYYY')or
DATE '2012-01-31'More related info
http://www.grassroots-oracle.com/2011/03/date-format-tolerance.html
Sorry if I'm off target, thought it may help -
I have a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".
USE [Runtime]
GO
/****** Object: UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt] Script Date: 06/11/2013 08:47:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)
-- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion
RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)
AS
BEGIN
-- Crea el Cursor
DECLARE cursorHora CURSOR
READ_ONLY
FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')
-- Declaracion de variables locales
DECLARE @produc_opt_hora int
DECLARE @produc_opt_parc int
DECLARE @nsacos int
DECLARE @time_parc datetime
-- Inicializamos VARIABLES
SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))
-- Abre y se crea el conjunto del cursor
OPEN cursorHora
-- Comenzamos los calculos
FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
/************ BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR ************/
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status = -2)
BEGIN
-- Terminamos la ejecucion
BREAK
END
-- REALIZAMOS CÁLCULOS
SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))
-- INSERTAMOS VALORES EN LA TABLA
INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)
-- Avanzamos el cursor
FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
END
/************ FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR ***************/
-- Cerramos el cursor
CLOSE cursorHora
-- Liberamos los cursores
DEALLOCATE cursorHora
RETURN
ENDYou can search the forums for that error message and find previous discussions - they all boil down to the same problem. Somewhere in your query that calls this function, the code invoked implicitly converts from string to date/datetime. In general,
this works in any version of sql server if the runtime settings are correct for the format of the string data. The fact that it works in one server and not in another server suggests that the query executes with different settings - and I'll assume for
the moment that the format of the data involved in this conversion is consistent within the database/resultset and consistent between the 2 servers.
I suggest you read Tibor's guide to the datetime datatype (via the link to his site below) first - then go find the actual code that performs this conversion. It may not be in the function you posted, since that function also executes other functions.
You also did not post the query that calls this function, so this function may not, in fact, be the source of the problem at all.
Tibor's site -
[Oracle 8i] How to convert a string (time stamp) into a date?
I'm having difficulty figuring out how to convert a time stamp string into a date (or possibly a number).
The time stamp is 20 positions, character (NOT NULL, CHAR(20))
in the format: YYYYMMDDHHMMSSUUUUUU
where Y = Year, M = Month, D = Day, M = Minutes, S = Seconds, and U = Microseconds
The reason I want to convert this is so that I can compare one time stamp to another (i.e. I want to be able to find the MIN(timestamp), MAX(timestamp), and do inequality comparisons).
Is this at all possible?
Thanks in advance for help on this!Hi,
As Damorgan said, if all you want to do is find which is the earliest or latest, then you can just compare the strings: they happen to be in a format where that works.
If you need to do other things, such as compare them to today's date, or see the difference between two of your rows in days, then you have to convert them to DATEs. (There's no point in converting them to NUMBERs).
A new data type, TIMESTAMP, which handles fractions of a second, was introduced in Oracle 9.
Since you're using Oracle 8 (according to your subject line), you either have to
(1) ignore the microseconds, or
(2) use a separate NUMBER column for the microseconds.
Either way, use TO_DATE to convert the first 14 characters to a DATE:
TO_DATE ( SUBSTR (txt, 1, 14)
, 'YYYYMMDDHH24MISS'
)where txt is your CHAR column.
To convert the microseconds to a number (between 0 and 999999):
TO_NUMBER (SUBSTR (txt, 15)) -
Conversion failed when converting date and/or time from character string
Hi experts,
I'm trying running a query in Microsoft Query but it gives the following error message:
"conversion failed when converting date and/or time from character string"
when asks me the data I'm inserting 31-01-2014
i've copy the query form the forum:
SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
CASE WHEN T0.TransType=13 THEN 'Invoice'
WHEN T0.TransType=14 THEN 'Credit Note'
WHEN T0.TransType=30 THEN 'Journal'
WHEN T0.TransType=24 THEN 'Receipt'
END AS 'Document Type',
T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
WHERE (T0.MthDate IS NULL OR T0.MthDate > ?) AND T0.RefDate <= ? AND T1.CardType = 'C'
ORDER BY T1.CardCode, T0.DueDate, T0.Ref1Hi,
The above error appears due to date format is differnt from SAP query generator and SQL server.
So you need convert all date in above query to SQL server required format.
Try to convert..let me know if not possible.
Thanks & Regards,
Nagarajan -
Converting a string into mySQL date format
I have a bit of code that collects data values from a bean and I want it to then insert this into a mySQL database. My string is in the format "23/12/1983", how can i put this into a date field in my database? The bit of code I have got so far looks like this...
String month = formHandler.month + "/";
String day = formHandler.day + "/";
String year = formHandler.year ;
StringBuffer sb = new StringBuffer();
sb.append(day);
sb.append(month);
sb.append(year);
String myDate = sb.toString();myDate is the value that I want to go into the databaseLimo2kz,
The key to inserting a date into a database is to convert the date string into an SQL friendly format. i.e. yyyy-MM-dd.
One way of doing this is as follows:
SimpleDateFormat NICE_DATE_FORMAT =
new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat SQL_DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
try {
date = NICE_DATE_FORMAT.parse(dateString);
} catch (ParseException pe) {
pe.printStackTrace();
String sqlDate = SQL_DATE_FORMAT.format(date);
Now it is just a matter of creating the insert statement like normal, and making sure that the date string is in quotes.
I hope that helps.
Damian Sutton -
SAP query error - 1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string. 'Received Alerts' (OAIB)
SELECT
CASE WHEN T0.DocStatus = 'O' THEN 'OPEN'
WHEN T0.DocStatus = 'C' THEN 'CLOSED' END AS 'Document Status',
T0.DocDate AS 'Posting Date',
T0.DocNum AS 'Doc.No',
T0.NumAtCard,
T0.TransId AS 'Trans. No.',
T0.Comments AS 'Remarks',
T0.CardCode AS 'Offset Acct',
T0.CardName AS 'Offset Acct Name',
sum(T0.DocTotal) + (T0.WTSum) as 'DocTotal',
T3.DueDate AS 'Cheque Date',
T3.CheckSum AS 'Amount'
FROM ODPO AS T0 LEFT OUTER JOIN
VPM2 AS T1 ON T0.ObjType = T1.InvType AND T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
OVPM AS T2 ON T2.DocEntry = T1.DocNum LEFT OUTER JOIN
VPM1 AS T3 ON T2.DocEntry = T3.DocNum
where T0.DocDate>='[%0]' and T0.DocDate<='[%1]'Hi,
Try this:
SELECT
CASE WHEN T0.DocStatus = 'O' THEN 'OPEN'
WHEN T0.DocStatus = 'C' THEN 'CLOSED' END AS 'Document Status',
T0.DocDate AS 'Posting Date',
T0.DocNum AS 'Doc.No',
T0.NumAtCard,
T0.TransId AS 'Trans. No.',
T0.Comments AS 'Remarks',
T0.CardCode AS 'Offset Acct',
T0.CardName AS 'Offset Acct Name',
sum(T0.DocTotal) + (T0.WTSum) as 'DocTotal',
T3.DueDate AS 'Cheque Date',
T3.CheckSum AS 'Amount'
FROM ODPO T0 LEFT OUTER JOIN
VPM2 T1 ON T0.ObjType = T1.InvType AND T0.DocEntry = T1.DocEntry
LEFT OUTER JOIN
OVPM T2 ON T2.DocEntry = T1.DocNum LEFT OUTER JOIN
VPM1 T3 ON T2.DocEntry = T3.DocNum
where T0.DocDate >= '[%0]' and T0.DocDate <='[%1]'
group by T0.DocStatus,T0.DocDate ,
T0.DocNum ,
T0.NumAtCard,
T0.TransId ,
T0.Comments ,
T0.CardCode,
T0.CardName ,
T0.WTSum ,
T3.DueDate ,
T3.CheckSum
Thanks & Regards,
Nagarajan -
Error in converting character string to smalldatetime data type
I've installed SQL Server 2000 on my new laptop and Crystal Report XI, out of sudden, the Crystal Report to certain view can't run and I got the following error:
Details: 22007 [Microsoft][ODBC SQL Server Driver][SQL SERVER]Syntax Error cnverting character string to smalldatetime data type.
Any suggestions?
HannahHere is the view the err is complaining about:
SELECT TOP 100 PERCENT Cur.Closed_Month, Cur.Closed_Year, Cur.Incidents_Closed, Prev.Incidents_Closed AS PrevIncidents_Closed,
YrAgo.Incidents_Closed AS YearIncidents_Closed
FROM (SELECT Closed_Month, Closed_Year, Incidents_Closed
FROM dbo.Incidents_Closed) Cur INNER JOIN
(SELECT Month(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevMonth,
year(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevYear,
Incidents_Closed
FROM dbo.Incidents_Closed) Prev ON Cur.Closed_Month = Prev.PrevMonth AND Cur.Closed_Year = Prev.PrevYear INNER JOIN
(SELECT Month(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevMonth,
year(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevYear,
Incidents_Closed
FROM dbo.Incidents_Closed) YrAgo ON Cur.Closed_Month = YrAgo.PrevMonth AND Cur.Closed_Year = YrAgo.PrevYear
What confused me is that it works fine with my previous laptop. I wonder if there is any patch in Crystal Report or SQL server that used to support certain functions but not support them anymore....
Thanks
Hannah -
Convert a string in dd/mm/yy form into a date in mm/dd/yy form
hi everyone
am having a problem.
i have a jsp page which receives a "request.getParameter("date")"
My user has input this date in the format dd/mm/yy
but i need to output this date to my db which accepts mm/dd/yy format.
Am thinking of implementing this in the follwing way
1:Since i have a string in dd/mm/yy form,i parse it to a date in this very format.
2:then i format it again to the mm/dd/yy form
3: i output it to the db
is this the correct way of doing it?
is there an easier way to convert a string in dd/mm/yy form directly into a date in mm/dd/yy form without getting a distorted value?
help me pleaseHi,
Parsing the date manually is a tedious task. If performance is not a issue, it is better to use SimpleDataFormat. Here is a sample code for converting the format:
String str = "01/02/1999";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date dt = sdf.parse(str);
sdf.applyPattern("MM/dd/yyyy");
System.out.println(sdf.format(dt));
Muthiah. -
How to convert a string into orcle date format
i need some information about converting string into date format.i have string like '20-SEP-05' .so we have to convert into date formate like yy-mm-dd' (2005-09-20).how can we do it.
Here's some code to help. I can't remember what method uses what format though
public static java.sql.Date sqlDateValueOf( String dateString ) {
String stringDate = null;
if ( dateString == null || dateString.length() < 10 ) return null;
String strDay = "";
String strMonth = "";
String strYear = "";
if ( dateString.substring(4,5).equals( "-" ) ) {
strDay = dateString.substring(8, 10);
if ( strDay.length() < 2 ) strDay = "0" + strDay;
strMonth = dateString.substring(5, 7);
strMonth = dateString.valueOf(Integer.parseInt(strMonth) - 1);
if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
strYear = dateString.substring(0, 4);
stringDate = strDay + "-" + strMonth + "-" + strYear;
else if ( dateString.substring(2,3).equals( "-" ) ) {
strDay = dateString.substring(0, 2);
if ( strDay.length() < 2 ) strDay = "0" + strDay;
strMonth = dateString.substring(3, 5);
strMonth = String.valueOf(Integer.parseInt(strMonth) - 1);
if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
strYear = dateString.substring(6, 10);
stringDate = strDay + "-" + strMonth + "-" + strYear;
Calendar cal = Calendar.getInstance();
cal.set( Calendar.YEAR, Integer.parseInt( strYear ) );
cal.set( Calendar.MONTH, Integer.parseInt( strMonth ) );
cal.set( Calendar.DAY_OF_MONTH, Integer.parseInt( strDay ) );
java.sql.Date outDate = new java.sql.Date( cal.getTimeInMillis() );
return outDate;
public static String toDateString( java.util.Date date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Date date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Date date, String format) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat( format );
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Timestamp date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
} -
How to convert character string into ascii format correctly
dear all
I'm using encryption technique in my application(oracle formas 6i). character stream convert to the ascii format and add some numeric value and again convert to the character format
>>>>
here I'm using ASCII and CHR functions.
>>>>
.net program also using same algorithm to encrypt this password.....finally both the character strings are not equel.(This happens if the character string's ascii value greater than 127. otherwise both are equel).
pls give me a solution for this
thanks and regards
buddhikehir dear
do u want to encrypt & dcrypt your password.which version of oracle you are using
first store these procedure in Oracle Databases: dbms_obfuscation_toolkit, dbms_crypto, Transparent Data Encryption
now u can use these procedure to encrypt & dcrypt your password
if you any query about those procedures you can ask me
best regard
amk -
Date Format Picture ends before converting entire input string..
Hi all
i am creating a report in 10g.. in which i want to convert Emp_lump_sum (number) to character .I have created a formula column in which i have written a function in the formula column and assign that formula column to the text field in which i want the result.
when the report run i get the following error....
ORA-01830: date format picture ends before converting entire input string..
i have tried with a attribute EMP_NO (Varchar2(30)), it shows the result but when i add EMP_LUMP_SUM (NUMBER) , it show the above error. on the database side i get the same error.
Database : 11g
OS : Windows server 2003
reports : 10g
any help will be thankful..
Function i wrote behind the formula coloumn is..
function CF_1Formula return CHAR is
xy varchar2(100);
begin
select to_char(to_date(emp_lump_sum,'j'),'jsp') into xy from fms_111_form4_tr;
return xy;
--xy := f_19;
end;Hello:
Try to use a database function and call it from reports.
Regards, -
Date time characteristic converted in a string in Universe OLAP
Hi there,
We are facing to the following issue. Maybe one of you has been already facing to.
We have created a BO universe on top of BI queries (based on MDX) and we make WEBI reports.
We note when we update/refresh the OLAP structure, all characteristics (Number and date) are converted/considered as a character and string and we loose in that way the time information.
This is very ennoying when sorting on time dimensions as WEBI can only sort on Alphabetic order.
Indeed, we would like to display the last 13 month of a key figure as from the last month.
As the time characteristic is automatically converted by the Olap refresh structure in a string, we can't display the last 13 months in logical/natural/calendar order.
Ex: NOV 2007 | DEC 2007 | JAN 2008 | FEB 2008 ....DEC 2008
Any idea :
- why the 'Refresh structure' command automatically convert into a string?
- how to force him not to convert to string and keep the date information?
- order date as the logical/natural/calendar one?
Beforehand, thanks a lotHi Ingo,
I'm using 0CMonth or 0CALMONTH which are SAP characteristics.
Do you know how to sort data by date and not by string?
When we recuperate infoobejcts from BI queriies, all objects are string and all LOV are sorted by string which don't help us.
imagine we have JAN 1996, JAN 1997,... FEB 1996 etc etc.
A nightmare
Laurent -
Judge weather a character-string can be convert to type QUAN
HI all.
Is there any Function that can judge weather a character-string can be convert to type QUAN?
IF no, could someone give me an efficient arithmetic.
Let me show my example:
FUNCTION z_judge_quan.
""Local interface:
*" IMPORTING
*" REFERENCE(STRING_IN) TYPE CHAR12
*" EXPORTING
*" REFERENCE(QUAN) TYPE BSEG-BPMNG
*" REFERENCE(MESSAGE) TYPE CHAR120
DATA: len TYPE i,
temp_str(20) TYPE c VALUE '00000000000000000000'.
DATA pos TYPE i.
DATA: a TYPE i.
DATA string(20) TYPE c.
DATA: off TYPE i.
DATA: string_temp(20) TYPE c.
string = string_in.
CONDENSE string NO-GAPS.
len = STRLEN( string ).
temp_str(len) = string.
a = len - 1.
string_temp = string.
CONDENSE string_temp.
FIND '.' IN string MATCH OFFSET off MATCH LENGTH pos.
REPLACE SECTION OFFSET off LENGTH pos OF:
string_temp WITH '|'.
IF sy-subrc <> 0.
IF temp_str CO '0123456789'.
message = 'Number'.
quan = string.
ELSE.
message = 'not number'.
ENDIF.
ENDIF.
IF sy-subrc = 0.
pos = sy-fdpos + 2.
FIND '.' IN string_temp." starting at pos
IF sy-subrc = 0.
message = 'not number'.
ELSE.
IF temp_str CO '0123456789.' AND temp_str0(1) <> '.' AND temp_stra(1) <> '.' .
message = 'number'.
quan = string.
ELSE.
message = 'not number'.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.Hi,
You can trap the exception as follows:
DATA: oref TYPE REF TO cx_sy_conversion_no_number.
DATA: oflow TYPE REF TO cx_sy_conversion_overflow.
data: c_menge type mseg-menge,
p_inp(16) type c value 'ABCDEFGH'.
TRY.
CLEAR oref.
c_menge = p_inp.
CATCH cx_sy_conversion_no_number INTO oref.
IF NOT oref IS INITIAL. "if error
message 'Not valid quantity'.
exit.
ENDIF.
CATCH cx_sy_conversion_overflow INTO oflow.
IF NOT oflow IS INITIAL. "if overflow.
CLEAR: p_inp.
message 'not valid quantity'
EXIT.
ENDIF.
ENDTRY.
Please award points if helpful..
regards,
S. Chandra Mouli. -
Convert a date in String format to a Date
Hi,
How can I convert a date in String format to a Date object?
I have tried:
import java.text.*;
import java.io.*;
import java.util.Date;
import java.util.Locale;
import java.sql.*;
public class casa {
public static Connection con = null;
public static Statement s = null;
public static String sql = null;
public static String mydate = "01.01.2001";
/** Creates a new instance of casa */
public casa() {
public static void main(String[] args) throws SQLException{
try {
DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
Date date = shortFormat.parse(mydate);
//Open Database
con = getConnection();
s = con.createStatement();
sql = "select date1 from table1 where date1 <= '"+date+"'";
ResultSet rs = s.executeQuery(sql);
while(rs.next()){
String aba = rs.getString("datum");
System.out.println("New Datum = "+aba);
} catch (Exception ex ) {
ex.printStackTrace();
closeConnection(s, con);
//Connection
private static Connection getConnection() {
Connection con = null;
String user ="aouzi";
String passe ="aouzi";
String url = "jdbc:db2:EjbTest";
try {
//Datenbanktreiber laden
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
//Verbindung herstellen
con = DriverManager.getConnection(url,user,passe);
}catch(ClassNotFoundException e){
} catch(SQLException e){}
return con;
//close Connection
private static void closeConnection(Statement s, Connection con) {
try {
s.close();
} catch (SQLException e) {}
try {
con.close();
} catch (SQLException e) {}
I'm getting the following errors:
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0180N
The syntax of the representation of a date/time of day value as character sequence is false. .SQLSTATE=22007I'm pretty sure it won't understand what date.toString() returns. If you know what format the database understands, you do it like this:
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy"); // e.g. 18-Apr-02
String datestring = sdf.parse(date);
and use that instead of date in your sql string. Some databases understands it if you do
"to_date('18-Apr-02')"
so you could include that in your sql string as well..
You could also try to make it a java.sql.Date and hope your jdbc driver knows how to convert it to a string that the database understands if you don't know the format:
con = getConnection();
PreparedStatement ps = con.prepareStatement("select date1 from table1 where date1 <= ?");
ps.setDate(new java.sql.Date(date.getTime()));
ResultSet rs = s.executeQuery(sql);
Maybe you are looking for
-
Soap Sender Adapter Deactivation
Hallo guys, we are working with an IP started by a Web Service call from a Business Service using a Soap Sender Adapter. Everything works. As we have to test also connections errors, we modify the Adapter setting status "Inactive". The intention is t
-
Group/Ungroup outline & Run macro automatically once open excel templates
Hi all, Would need your advise for the following queries. 1. May we have a protected sheets with Group/Ungrouped features? 2. Is there a way to auto-run the macro once we open excel template? Looking forward to hear from you all! Thank you very much!
-
You guys, I need a radix sort algorithm for java. I've worked on it for a while, and I cant get it. I have this so far: public void radixSort(int maxDigits) Vector temp = new Vector(); int count = 1; while(count<(Math.po
-
Trying to downloads App store application for the sole pupose of downloading a purchased OS update 10.7. We cannot download the app store until we have a software update but need the software update to download the app store.
-
Variants Values in BI 7.0 New Reporting Tools
Hello SDN, We had an OSS Message (204968) to address the issue where we are NOT able to see query "predefined" Variants values in new reporting tools BI 7.0 BEx Analyzer. SAP support has responded saying they are able to see the Variants values. We'