on 06-13-2005 1:49 PM
hi,
i have a table which contains the data type and timestamp type. I am setting up prepared statements - however i have difficulties getting the date right.
I searched help.sap.com and found this code:
import java.sql.SQLException;
String dateString = "2003-03-24";
java.sql.Date date = new java.sql.Date.valueOf(dateString);
PreparedStatement stmt =
conn.prepareStatement("insert into RESERVATION "
+ "(ID, RESERVATION_DATE)"
+ "values (23, ?)");
try {
stmt.setDate(1, date);
stmt.executeUpdate();
} finally {
stmt.close();
}
i've got the import correct and tried the code but i get the "cannot be resolved or type" error.
How do I get that straight?
thanx in advance, matthias
Hi matthias,
Have you imported class PreparedStatement ?
It seems that java runtime cannot resolve one of your symbols, maybe the PreparedStatement class.
Try adding import java.sql.PreparedStatement and let us know
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I 've got all the imports correct, i reckon.
At least I have got this bunch of guys in my java-file:
package com.wd.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.<b>PreparedStatement</b>;
import java.sql.ResultSet;
import java.sql.<b>SQLException</b>;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import com.wd.vo.Row;
import com.wd.vo.Table;
I also tried
import java.sql.Date;
but in my method I get the error:
the method goes like this:
public void insert(Row row) throws SQLException {
String dateString = "20031212";
java.sql.Date ndate = new java.sql.Date.valueOf(dateString);
PreparedStatement pstmt3 =
con.prepareStatement("insert into TAB_VORGANG " +
"(VORNR, BETRIEB, CREA_DATE) values (?,?,?)");
pstmt3.setString(1, row.getVornr());
pstmt3.setString(2, row.getBetrieb());
pstmt3.setDate(3, ndate);
pstmt3.execute();
pstmt3.close();
}
and <i>java.sql.Date.valueOf</i> is underlined red.
Hi Ashuto
ok - I tried:
Date dt;
dt.setDate(24);
dt.setMonth(3);
dt.setYear(2005);
PreparedStatement pstmt3 =
con.prepareStatement("insert into Tab_VORGANG " +
"(VORNR, BETRIEB, CREA_DATE) values (?,?,?)");
pstmt3.setString(1, row.getVornr());
pstmt3.setString(2, row.getBetrieb());
pstmt3.setDate(3, dt);
now in the last line dt turns red - and the above declarations are marked as deprecated (which i experienced before - apparently we shall use the Calendar now)
Hi,
Try this !
Date d = wdContext.currentContextElement().getExpecteddate();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
String date = sdf.format(d);
Pass this string.. and instead of using setDate .. use setString and give this string value.
It will be automatically set as date in Oracle.
Regards
Bharathwaj
Guys, now i really get trouble.
the webdynpro-view which interacts, with the connection.java
is breaking up - even though i commented all relevant source I get an error in this standard line
" private final IPrivateView1 wdThis;" with corresponding further errors.
I tried to repair an rebuild - no effect.
How did this happen?
Hi
if u lost ur wdThis, wdContext etcc.
try checking for an error in the Task View where there will be single error standing alone try rectifying that and it will automatically solve the remaining errors.
That error will not be merger with the general errors.
try identifying that
Wishes
Krishna kanth
Concerning my date format problem - as Ashutosh Moharir stated "java.sql.Date dt=new Date(System.currentTimeMillis());" I get no error with that code, but neither an entry in my db-table.
What I did is creating a db-tab in the Java Dictionary and deployed it to the J2EE. To the date field I assigned the type "date". Strangely my Quantum Eclipse Plugin tells me the length of the date field to be only (7).
I wonder which kind of date fits in there??? also string fields which I assigned a certain length appear to have a different length-value as shown in my quantum tool...
So - who to believe-NWDevStudio or Quantum or what???
Thanks for some light on that issue, too.
Matthias
Message was edited by: matthias kasig
Hi Bharathwaj R,
you are right - the date format is like 23Feb2005 - in the db it appears as 2005-02-23 00:00:00.0
now right before the insert i created this, almost like you proposed (because I don't need a context here) - i simply need the actual date right here:
java.sql.Date kd_date = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat(<b>"dd-MMM-yyyy"</b>);
kd_date.getTime();
String date = sdf.format(kd_date);
and then stmt.setDate(3, date);
not stmt.setString... this would not work.
still i get no entry in my db-tab...
Message was edited by: matthias kasig
Hi,
Only if use the string the whole process of getting in that format will work.. Since u r using the date again directly... it wont make any difference
Did u check with setString.. Because i had a pretty similar situation. For date field i gave it in the string format ..(Only difference was i dint use a prepared statement!).
Are all other datas in that record entered.
If u r using EJB throw the Exception in the particular function.. catch it in WebDynpro and see what it is saying.
Regards
Bharathwaj
Message was edited by: Bharathwaj R
hi Bharatwaj,
i am using JDBC - my java skills are more or less basic.
i have a row.java which describes the table-row and a table.java which creates the table based on row.java.
Now i noticed, that in my row.java I set the attributes (also for date and time as String). Is that correct?
public class Row
{
private String vornr;
private String kd_date;
private String kd_time;
...
Hi,
I am not very clear about how you are using this class.
But if u r using this class to get the values in the prepared statement. And are u setting the date inside a function in that class.
If so then make it string and assign to the simpledateformat string value and set it in the prepared statement .
Regards
Bharathwaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Check all the errors..Check the last error in that list.. You might have missed some binding ?
Due to that one error the whole code will go haywire .If u solve that it will work..
Regards
Bharathwaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok,
try this code then
Date dt;
dt.setDate(24);
dt.setMonth(3);
dt.setYear(2005);
......
......
stmt.setDate(1, date);
Tell me the result.
Ashutosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Matthias,
try
String dateString = "20050324";
and let me know the result.
Ashutosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.