473,378 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

changing the system date from javacode

Hi ,

I want to change the system date using java/jsp . i am using linux system .

public class LinuxJava {
public static void main(String[] args) {
try {
String command = "date 07212008";
final Process process = Runtime.getRuntime().exec(command);

// int returnCode = process.waitFor();
// process.toString()
System.out.println("Return code = " + process.toString());
} catch (Exception e) {
e.printStackTrace();
}
}

}

i tried this code it didn't change the code . can any one tell how to change the system date with java application ?
Jul 21 '08 #1
11 11222
JosAH
11,448 Expert 8TB
What *did* it do? What was the completion code of the process? Any exceptions
thrown? Is the effective user allowed to change the system date?

kind regards,

Jos
Jul 21 '08 #2
no exception thrown it is executing the code but it is not chaning the date .

for chaning the date we need to have root permision . may be beacuse of that it is not executing .

i tried with this command also

String command = "date -s 'Sat May 24 14:43:00 PDT 2005' "; in place of
String command = "date 07212008'
Jul 21 '08 #3
JosAH
11,448 Expert 8TB
no exception thrown it is executing the code but it is not chaning the date .

for chaning the date we need to have root permision . may be beacuse of that it is not executing .
Sure, you have to be root to change the system date so you have to run your
little program with an effective uid set to root.

kind regards,

Jos
Jul 21 '08 #4
samido
52
I am not sure what this suppose to do but the type of exception is as follow, somebody please help out so that we can all learn this thign

java.io.IOException: Cannot run program "date": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Test.main(Test.java:16)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more

kind regarde:

Sam Rabophala
Jul 21 '08 #5
i have changed the class file user as root but still it is not working .
anything else i need to do ?



Sure, you have to be root to change the system date so you have to run your
little program with an effective uid set to root.

kind regards,

Jos
Jul 21 '08 #6
i tried by writing the one shell script with root permision .

# Author: Rashmi
# date : 01-07-2005

date -s 'May 12 2008'


and calling that one with java code

public class LinuxJava {
public static void main(String[] args) {
try {
String command = "/home/rashmi/test.sh ";
final Process process = Runtime.getRuntime().exec(command);

// int returnCode = process.waitFor();
// process.toString()
System.out.println("Return code = " + process.toString());

} catch (Exception e) {
e.printStackTrace();
}
}

}


it is also executing .. but not chaning the date :(
Jul 21 '08 #7
JosAH
11,448 Expert 8TB
i tried by writing the one shell script with root permision .

[ ... ]

it is also executing .. but not chaning the date :(
If you run that script manually, does it change the date?

kind regards,

Jos
Jul 21 '08 #8
now i am able to change the date , i changed the tomcat user to root . and script user to root . now it started working .
thanks
Jul 24 '08 #9
r035198x
13,262 8TB
now i am able to change the date , i changed the tomcat user to root . and script user to root . now it started working .
thanks
Oh so Tomcat was involved in all this? I didn't pick that up from your ealier posts in this thread.
Jul 24 '08 #10
i wanted do this either by the stand alone java program or from the application .
after chaning the tomcat to root user , i called the java program program from jsp . then it started working .
Jul 24 '08 #11
hi ksrashmi,

can you please paste the content that was there in
/home/rashmi/test.sh.

Thanks,
Pradeep.
Aug 4 '16 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make...
1
by: Robert Bravery | last post by:
HI all, I am new to .net and c#. How can I change the system date based on user input on an textbox on a form Thanks Robert
5
by: Mark Fox | last post by:
Hello, When you add a new web form in VS.NET it automatically adds the following namespaces at the top: using System; using System.Collections; using System.ComponentModel; using...
0
by: gh0st54 | last post by:
Hi i'm looking for how to change the date of out going messages i tried this but it doesn't seems to work static public bool SendEmail(string To, string From, string Subject, string Body,...
2
by: barry | last post by:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim curtime As Date Do Until Date.Now >= some future date time curtime = Date.Now...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
0
by: jeanuta | last post by:
boolean retval = false; StringBuffer sql = new StringBuffer(); ResultSet rst = null; conn.setAutoCommit(false); sql.append("select assign_customers() "); Statement st =...
18
JamesDC
by: JamesDC | last post by:
Hi, So I'm working with an Access 2002 database for waste managemnt. The person in my role before my put together the program before he left and now I'm in charge of it. After updating a few...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.