MS Access Date problem (from Java program)
I have written an app. in Java that reads & writes data from a MS Access database.
I am trying to write an insert class which will add a row of data to one of my database tables - which contains Date fields.
My problem is that I can update the text fields, but not Date fields - every time I try my program throws an exception:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement
My simplified code reads as:
try {
Statement insertStatement = databaseConnection.createStatement();
String query = "INSERT INTO myTable(jobId, employeeId, date) VALUES('11', '1', " + "'13/11/2006'" + ");";
insertStatement.execute(query);
} //close, etc. etc.
If I remove the date info from the query, the program executes successfully. I appreciate my problem might be related to the formatting of the date in Access, and if not a 'proper' Java question I give my apologies.
I have attempted several formats of the date with no success or variation in the exception.
I am, however, completely stuck and would appreciate any and all help given.
Regards and thanks
David
I have amended my code to use a preparedStatement, but on execution I have the same problem.
My code is as follows:
PreparedStatement pstmt = null;
try {
String query = "INSERT INTO myTable (jobId, employeeId, date) VALUES(?, ?, ?);";
pstmt = databaseConnection.prepareStatement(query);
pstmt.setString(1, "11");
pstmt.setString(2, "1");
java.sql.Date sqlDate = getCurrentJavaSqlDate();
pstmt.setDate(3, sqlDate);
// execute query, and return number of rows created
int rowCount = pstmt.executeUpdate();
System.out.println("rowCount=" + rowCount);
pstmt.close();
catch, etc. etc.
Any ideas or help most welcome
Regards
David
Similar Messages
-
Access SAP Tables from Java Program
Hi All,
We have a requirement to integrate attendance portal(which is done in java) with SAP.
Our problem is how to access SAP tables from a Java program?
Database is Sybase.
Please suggest us a good solution.
Thanks in advance...Did you go through Sap Help?
Calling BAPIs from Java - BAPI User Guide CA-BFA) - SAP Library
Regards,
Philip. -
How to access system calls from java program?
i am having a doubt regarding accessing system calls from a Java program like accessing unix system calls from a c program.
Runtime.getRuntime().exec("line command here");
example:
Runtime.getRuntime().exec("ls -la"); -
How to edit the existing data in the XML file from java programming.
Hi all
i am able to create XML file with the sample data as below from java programming.
i need sample code on how to edit the existing data in the XML file?
for example
<?xml version="1.0"?>
<mydata>
<data1>
<key1>467</key1>
<name1>Paul</name1>
<id1>123</id1>
</data1>
<data2>
<key2>467</key2>
<name2>Paul</name2>
<id2>123</id2>
</data2>
</mydata>
i am able to insert the data in the XML.
now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
Regards
Sunil
[points will be always rewardable]hi
u need a parser or validate the xml file for to read the xml file from java coding u need for this
xml4j.jar u can download this file from here
http://www.alphaworks.ibm.com/tech/xml4j
or we can use the SAX(simple API for XML)
some sample applications for this
http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
http://www.xml-training-guide.com/e-xml44.html
let me know u need any other info
bvr -
How to access database file on CDROM from Java Programe??
Hello friends,
I am making online exam application.
I want my question database to be reside on CDROM.
but i am not getting any idea how to make DSN or static path that resolute the path that i have mentioned for CDROM.
basically i want to know how to access CDROM from Java Programe????
Thanks in advance
Navik PathakOnce you mounted the CDROM (something maybe as /media/cdrom) as a file system (or assigned a drive letter to it like D: or F: or whatever), the files are accessible normally.
-
Problem while running dos command from java program
Dear friends,
I need to terminate a running jar file from my java program which is running in the windows os.
For that i have an dos command to find process id of java program and kill by using tskill command.
Command to find process id is,
wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
Code to run this command is,
public class KillProcess {
public static void main(String args[]) {
KillProcess kProcess = new KillProcess();
kProcess.getRunningProcess();
kProcess = new KillProcess();
kProcess.readProcessFile();
public void getRunningProcess() {
String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
try {
Runtime run = Runtime.getRuntime();
Process process = run.exec(cmd);
int i = process.waitFor();
String s = null;
if(i==0) {
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println("--> "+s);
} else {
BufferedReader stdError = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
while ((s = stdError.readLine()) != null) {
System.out.println("====> "+ s);
System.out.println("Running process End....");
} catch(Exception e) {
e.printStackTrace();
public String readProcessFile() {
System.out.println("Read Process File...");
File file = null;
FileInputStream fis = null;
BufferedReader br = null;
String pixieLoc = "";
try {
file = new File("ProcessList.txt");
if (file.exists() && file.length() > 0) {
fis = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
} else {
System.out.println("No such file");
} catch (Exception e) {
e.printStackTrace();
return pixieLoc;
} when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
if i give process.waitFor(), then it's in running mode and program is not completed.
Colud anyone please tell me how to handle this situation?
or Is there anyother way to kill the one running process in windows from java program?
Thanks in advance,
SathishHi masijade,
The modified code is,
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is, "UTF-16");
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodWindowsExec
public static void main(String args[])
try
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
if( osName.equals( "Windows 95" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
} else {
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
System.out.println("Executing.......");
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
}when i execute the above code, i got output as,
Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
and keeps in running mode only.
If i execute the same command in dos prompt,
CommandLine
ProcessId
java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP 2468
If i modify the command as,
cmd.exe /C wmic process where "name='java.exe'" get commandline,processid > 123.txt
and keeps in running mode only.
If i open the file when program in running mode, no contents in that file.
If i terminte the program and if i open the file, then i find the processid in that file.
Can you help me to solve this issue? -
Want to access RESTful Services through Java Program
We are trying to access RESTful Services exposed by Oracle database cloud through our Java code, with authentication enabled for a particular user.
Till now, we have completed below steps:
1) We have a working account with Oracle database cloud (Username – xxx.xxx)
2) We log in using the credentials for above account, and navigate to Oracle Apex ? SQL Workshop ? RESTful Services
3) We create a new “RESTful Service Module” by filling out the details as below:
Name: SampleTest
URI Prefix: test
URI Template: /getallemp
Pagination Size: 25 (kept to default)
Required Privilege: TestGroupPrivilege
Resource Handler Details:
Method: GET
Source Type: Query
Format: JSON
Source: select * from emp
After creating the above module and testing it, it works fine and the data is retrieved in JSON successfully.
The resulting URL for above RESTful Service Module is: https://<HOST_URL>/apex/test/getallemp
Note that “TestGroupPrivilege” is a privilege assigned to the user group “RESTful Services” and the user “xxx.xxx” is a member of “RESTful Services” user group.
4) We are unable to call the RESTful services from Java program. We are passing username and password in request header as basic authentication. But, we are getting: Error 500--Internal Server Error
5) If we change the “Required Privilege” to default i.e. no privileges present on the module, we can get the response through Java code and everything works perfectly fine.
Please suggest us in: How to access RESTful Services through Java code by passing user credentials in HTTP header for authentication. Also let us know if we have to do any settings through Apex, in case we are missing any.
Message was edited by: NeerajGirolkar
- When we are logging in to Oracle cloud on browser and execute the Oracle cloud RESTful service in another tab of same browser, we are able to get the result. But when executed the same RESTful service from a different browser or java program we get internal server error.
- After investigation, we found that when user logs in to oracle database cloud, a cookie is set in browser with name s “OAMAuthnCookie_cstest-domo.db.us1.oraclecloudapps.com:443” and value as some random token. This cookie is passed in the subsequent requests to the RESTful Service calls when using same browser and as a result, we are able to get the results
- In the Java program, we copied the same cookie with random token in the HTTP Request header and we got the proper response from REST APIs.
- It seems that this cookie is created by an Oracle Middleware tool/server called as OAM – Oracle Accounts Manager, which sends the authentication token after successful authentication and creates the cookie.
- We found that the cookie that OAM creates on authentication is exactly in the same format i.e. ‘OAMAuthnCookie_cstest-domo.db.us1.oraclecloudapps.com:443’. So, we are guessing that Oracle cloud uses OAM for authentication. Please refer to following link for same : http://docs.oracle.com/cd/E14571_01/doc.1111/e15478/sso.htm
Can anyone please suggest:
1. How to provide authentication to Oracle Cloud REST APIs from java program?
2. How to pass the username and password in Java code to OAM (or how to communicate with OAM using Java) so that we can receive the unique token from OAM. We can use the token in the further requests? 3. Also in Oracle cloud white papers , it is mentioned that they support OAuth2.0. But we didn’t find any URLs for same. Can anyone please confirm?
Thanks
~ Neeraj GirolkarHi Nilesh,
We tried to connect to Oracle Cloud Database using the way you suggested above, but unfortunately it is not working as well.
Can you let us know the authentication process with Oracle Cloud Database? We found in documentation that it uses OAM (Oracle Access Manager) for authentication. Can you tell us a bit about that? That will be extremely helpful.
Thanks,
- Neeraj -
How to Access Maintenance View from a program
Hi Experts,
I have created a maintenance view for a table. i want to insert data's into the table through the maintenance view. I don't know how to access the view, how to insert data into the Maintenance view. Please suggest me how to access the view from the program.
with regards,
James...
Valuable answers will be rewarded...Hi,
What is the need to search for a program.
Use transaction SM30 or SE16 to create or maintain entries in the table.
e.g. if the Maintenance view is created on table A, then Goto transaction SM30 or SE16 and give the table name as A and proceed. This will automatically take u to the maintenance view on tha table A.
Regards,
Himanshu -
Am trying to access MS SSAS data cube from Java through olap4j driver(through msmdpump.dll). I am able to connect , but when I try to execute a query, i am getting the below error: Please help
me out . (I tested the http://XXXX/OLAP/msmdpump.dll in MS Excel , and it is working fine)
org.olap4j.OlapException: XMLA provider gave exception: <soap:Fault xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>
XMLAnalysisError.0xc10a0004
</faultcode>
<faultstring>
The CRASHDWHSRG cube either does not exist or has not been processed.
</faultstring>
<detail>
<Error Description="The CRASHDWHSRG cube either does not exist or has not been processed." ErrorCode="3238658052" HelpFile="" Source="Microsoft SQL Server 2012 Analysis Services">
</Error>
</detail>
</soap:Fault>See my other answer where you asked this same question on another thread
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/22dfc400-668d-4bd4-b76d-7c6b9ddda47a/msmdpumpdll-not-getting-registered?forum=sqlanalysisservices
http://darren.gosbell.com - please mark correct answers -
Since installing Photoshop CC I can't access Camera Raw from the program Bridge.
Since installing Photoshop CC I can't access Camera Raw from the program Bridge. When I try, I get a message that says, "Camera Raw editing is not enabled. Camera Raw editing requires that a qualifying product has been launched at least once to enable this feature." Is Photoshop CC a qualifying product? It has been opened a number of times, but it doesn't solve this problem.
I am having this exact same problem and just upgraded to Windows 7...many people are saying to update the Plug In for Camera Raw to 4.6, but that is not working for me to see it in Bridge or Camera Raw.
-
Calling oracle SQL Loader from java program
Hi,
I want to insert data into oracle tables from a text files containing fixed length fields. I am using SQLLoader to achieve this. The requirement is to call the SQLLoader within the java program.
Does anyone know how to call SQL Loader from java program?
Thanks,
VarshaSimply "exec" the sqlldr program with the parameters you need to pass to it.
Runtime.exec (........)
Try to pass all parameters needed including the username and password, and use the option "silent" to avoid output, and the option "log" to have a log file of the modifications that sqlldr has done to the database. -
How to connect iseries green screen from java program
how to connect iseries green screen from java program to get the data in the DB files ,here the DB is DB2/400
Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
import java.io.*;
import java.net.*;
public class AutoTelnet {
private static Socket s;
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
@Override public void run() {
try {
s = new ServerSocket(5555).accept();
} catch (IOException ex) {
ex.printStackTrace();
t.start();
Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
t.join();
PrintStream ps = new PrintStream(s.getOutputStream());
ps.println("Screen will be cleared in 5 seconds");
ps.println("5");
Thread.sleep(1000);
ps.println("4");
Thread.sleep(1000);
ps.println("3");
Thread.sleep(1000);
ps.println("2");
Thread.sleep(1000);
ps.println("1");
Thread.sleep(1000);
ps.println("\u001b[2J");
Thread.sleep(5000);
} -
Starting weblogic server from java program
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd /c d:/bea/weblogic700/server/bin/setWLSEnv.cmd");
when ihave given like this it is working.
now i want to start weblogicserver from jav program
String s="-Dweblogic.Domain=mydomain weblogic.Server"
Process p=r.exec("cmd /c d:/bea/weblogic700/server/bin/setWLSEnv.cmd java "+s);
when i gave like this weblogicserver should start with specified domain
but no output is comming.please tellme where the problem isno - nothing happened. it perform the next java code - and there is nothing else happen on the windows.
maybe i don't check in the right place for the error you are talking about?
i also tried i simple cmd file that does nothing - but still nothing...
for any other file types it works properly. -
Downloading unix archive file (.Z extension) from java program
Hi,
I am trying to download unix archive files with .Z extension from java program. When I use
BufferedReader zReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
and then read line by line and write it to file, downloaded file can't be decompressed. I tried to open it with winZip which supports .Z files but I get the message : Cannot open file, it does not appear to be a valid archive.
How can I download file correctly?
Any help would be appreciated.Hi,
I am trying to download unix archive files with .Z
extension from java program. When I use
BufferedReader zReader = new BufferedReader(new
InputStreamReader(urlConn.getInputStream()));
and then read line by line and write it to file,How are you writing the file? Since it is binary data you need to be careful about using Reader/Writers, which are meant for character data. Look at using classes from the InputStream/OutputStream hierarchy.
- N -
Hi all,
How to change a date value from "java.util.Date" to "java.sql.Date"?
I m still confusing what's the difference between them.....
thanks
Regards,
KinThanks
but my sql statement can only accept the format (yyyy-MM-dd)
such as "select * from xx where somedate = '2004-12-31'
but when i show it to screen, i want to show it as dd-MM-yyyy
I m using the following to change the jave.util.Date to str and vice versa. But it cannot shows the dd-MM-yyyy. I tried to change the format from yyyy-MM-dd to dd-MM-yyyy, it shows the wrong date in my application.
public String date2str(java.util.Date thisdate) {
if (thisdate != null) {
java.sql.Date thissDate = new java.sql.Date(thisdate.getTime());
return date2str(thissDate);
} else {
return "";
public String date2str(java.sql.Date thisdate) {
if (thisdate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(thisdate);
} else {
return "";
public java.util.Date str2date(String thisdate) {
String dateFormat = "yyyy-MM-dd"; // = 1998-12-31
java.util.Date returndate = null;
if (thisdate != null) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
try {
returndate = dateFormatter.parse(thisdate);
} catch (ParseException pe) {
System.out.println (pe.getMessage());
return returndate;
}
Maybe you are looking for
-
How do I display multiple pdf documents in the same window?
I am sure that this question has been asked many times before, but I have searched the forums and the online help documentation for nearly 45 minutes without a satisfactory answer. I have just installed the trial version of acrobat pro and I want to
-
URL to download BO XI 3.1 SP3 Integration kit for SAP Solutions
HI I have Installed BO XI 3.1 SP3 Enterprise in the server.I want to Install BO XI 3.1 SP3 Integration kit for SAP solutions. 1)I want to know what is the order of Installations i need to install in case of Crystal Reports and Xcelsius,BI,SAP GUI. 2)
-
LOST IPHONE 5 Can I GET AN REPLACEMENT
I have recently lost my Iphone 5 on pay as you go. I was wondering whether or not i would be covered by any waranties? And If So ... Can I go to the apple shop and show them my reciepiet and will they give me a replacement?
-
Is possible buy the IPAD air open to any celular companies?
is possible buy the IPAD air open to any celular companies?
-
Why won't final cut pro x let me "export movie"?
Every time i select the export movie option nothing happens. No windows or messages appear. Please help!