Problem using UPDATE command from Java
I am getting an error when I use the following code in my java file and use it in JSP through beans:
sql = " UPDATE SHOPPINGCART SET QUANTITY='"+quant+"' WHERE USERNAME ='"+username"' AND TOYID='"+toyid+"' ";
CM.executeUpdate(sql); //CM is the connection object and I have a method which inturn calls executeUpdate
This is the error
C:\Program Files\Apache Software Foundation\Tomcat 4.1\webapps\DBTest\WEB-INF\cl
asses\user>javac *.java
ToyDBAO.java:124: ';' expected
+"WHERE USERNAME ='"+username"' AND TOYID='"+toyid+"' ";
^
ToyDBAO.java:124: not a statement
+"WHERE USERNAME ='"+username"' AND TOYID='"+toyid+"' ";
^
2 errors
Please reply
Message was edited by:
aniketh_parmar
Now the prob is that its compiling the java file. But when I run the program, an error is caught
sql = " UPDATE SHOPPINGCART SET QUANTITY='"+quant+"' (WHERE USERNAME ='"+username+"' AND TOYID='"+toyid+"')";
This is the error in tomcat window
Message Error:You have an error in your SQL syntax; check the manual that corres
ponds to your MySQL server version for the right syntax to use near '(WHERE USER
NAME ='aniketh_parmar' AND TOYID='3')' at line 1
Similar Messages
-
Error using DOS Command from Java
Hi,
I am using the following code to execute the DOS command to delete a file from Java.
cmd = "del " + fileName;
Runtime run = Runtime.getRuntime();
Process proc = run.exec(cmd);
Getting the following exception during runt time.
Exception = java.io.IOException: CreateProcess: del D:\LAWDOCS\P50074\12\3\36857.3 error=2 --
Can some body throw light on this?.
Thanks,
Jeyaraman R"del" is not an actual executable file, but instead a command in the command interpreter. So you can't just execute del like that, you have to run the command interpreter and tell it to execute the del command.
If you are on windows NT, 2000 or XP, replace your command with "cmd /C del " + filename.
If you are on Windows 95, 98 or ME, use "command /C del " + filename. (I am not quite sure if the switch for this is called /C on old windows version.)
(But why not use File.delete()?) -
Using Unix commands from Java Application
Hi,
I need to write an Java application such that could run Unix commands in a Unix box.
For example, my Java app needs to log in the Unix box, change directory (cd), create new folder (mkdir), list the current files in folder (ls), mount a new device (mount), etc.
Thank you very much.
Hungyou can use java.lang.Runtime.exec to invoke OS commands, but if you're going to be completing a sequence that complicated and need to manage error handleing well, it might be best to just invoke a native method or write a shell script that does all of that stuff and then invoke that script via Runtime.exec . The Runtime class has limitations when you start invoking processes that require user input (like 'su'). Search the forums for more extensive examples on how to use Runtime.
-
Running OpenVMS DCL command from Java
Hi,
I want to execute an Alpha OpenVMS 7.2-2 command from Java. I use JDK 1.1.8-1.
I have to place the DCL command in an OpenVMS .COM file because passing a DCL
image like DIR doesn't work using Runtime.exec().
When I ran the Java program, I get the following error:
java.io.IOException: Child creation error: exec format error
at java.lang.UNIXProcess.<init>(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at oscmd.main(Compiled Code)
here is my Java program:
import java.io.*;
public class oscmd {
public static void main(String[] args) throws Exception {
Process child = Runtime.getRuntime().exec(
"dra1:[oracle8.db_adamp.backup]RUNCMD.COM");
child.waitFor();
child.exitValue();
child.destroy();
Thanks for your help.Hi,
Did you get your exec format error problem?
I'm having exactly the same problem and would greatly appreciate any help you could offer.
Thanks
Tim -
Running ls command from Java stroed procedure no output
Hi ,
I am trying to run ls command from java stored procedure in oracle
Process p = Runtime.getRuntime().exec("ls");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("output of the command run:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
from java stored procedure in oracle.
i get output of println statments but it does not go into while loop to print from stdInput.
Result of running Java stored procedure is -
output of the command run:
Call completed.
when i run the program on client side it works fine.
Has anybody tried this from java stroed procedure.
Thanks,
JagJag,
Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
SQL> /
output of the command run:
init.ora
initDBPart9i.DBPSun01.ora
initdw.ora
lkDBPART9I
orapw
orapwDBPart9i
spfileDBPart9i.ora
Done
PL/SQL procedure successfully completed.
But, I did need to change a line of your code to this:
Process p = Runtime.getRuntime().exec("/usr/bin/ls");
your original was:
Process p = Runtime.getRuntime().exec("ls");
You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
Hope this helps,
-Dan
http://www.compuware.com/products/devpartner/db/oracle_debug.htm
Debug PL/SQL and Java in the Oracle Database -
Problem using jsp:include from inside a custom tag
Hi, All !
I have a problem using <jsp:include> from inside a custom tag. Exception is:
"java.lang.ClassCastException: weblogic.servlet.jsp.BodyContentImpl"
Apparently, weblogic tries to cast BodyContentImpl to JspWriterImpl and
could not do this. Is it a bug, since in the 1.1 spec is said: "The
BodyContent is a subclass of JspWriter that can be used to process body
evaluations so they can retrieved later on."
My code is:
<wfmklist:items>
<jsp:include page="item.jsp" flush="true"/>
</wfmklist:items>
This is an area of contention with WL. It is not so tolerant with regards to
the spec. I spent several days recently trying to convince it to accept the
specification in regards to bodies and includes and it appears to have
successfully rebuffed my efforts.
Frankly, this is very disappointing. It appears that some shortcuts were
taken on the way to JSP 1.1 support, and the result is a very hard-coded,
inflexible implementation. As I have not seen the implementation myself, I
hate to assume this, however one could posit that the term "interface" was a
foreign concept during the implementation, other than as some annoying
intermediary reference requiring an immediate cast to a specific Weblogic
class, which in turn is apparently required to be final or have many final
methods, as if being optimized for a JDK 1.02 JIT.
I am sorry that I don't have any positive suggestions other than to use a
URL object to come back in an execute the necessary "include" directly. You
lose all context (other than session) and that can cause its own problems.
However, you can generally get the URL approach to work, and you will
hopefully avoid further frustration.
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
Tangosol: How Weblogic applications are customized
"Denis" <[email protected]> wrote in message
news:[email protected]...
> Hi, All !
> I have a problem using <jsp:include> from inside a custom tag. Exception
is:
> "java.lang.ClassCastException: weblogic.servlet.jsp.BodyContentImpl"
>
> Apparently, weblogic tries to cast BodyContentImpl to JspWriterImpl and
> could not do this. Is it a bug, since in the 1.1 spec is said: "The
> BodyContent is a subclass of JspWriter that can be used to process body
> evaluations so they can retrieved later on."
>
> My code is:
> ...
> <wfmklist:items>
> <jsp:include page="item.jsp" flush="true"/>
> </wfmklist:items>
> ...
-
Call an interactive UNIX command from java
Hi,
I want to call a UNIX command from java. When issue the command 'htpasswd -c filename username' on UNIX terminal, it asks for the new password and the then confirmation password again (yeah, unfortunately the htpasswd installed on our system does not allow you proivde the password on the command line. So have to work interactively ). Now, I have written a simple java program RunCommand.java. I am hardcoding the password for the htpasswd command in the file (in the real situation, password will be generated dynamically). I want to issue 'java RunCommand' on the UNIX command line and get back the command prompt without being asked for the password twice. The code is below, but the Outputstream does not work as expected. It always asks for inputs. Any idea? Many thanks.
import java.io.*;
public class RunCommand {
public static void main(String args[]) throws Exception {
String s = null;
try {
String cmd = "htpasswd -c filename username ";
// run a Unix command
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
OutputStream stdOut = p.getOutputStream();
String pswd = "mypassword";
while ((s = stdInput.readLine()) != null) {
s = stdInput.readLine();
stdOut.write(pswd.getBytes());
stdOut.flush();
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
stdOut.close();
stdInput.close();
stdError.close();
System.exit(0);
catch (IOException e) {
System.out.println("exceptions caught: ");
e.printStackTrace();
System.exit(-1);There are only about 9 billion responses a day on how to do this. Use the search feature.
-
How to execute Linux command from Java app.
Hi all,
Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
Thanks a lot,You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
java.io.BufferedReader br =
new java.io.BufferedReader(new java.io.InputStreamReader(
Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
getInputStream()));
while ((s = br.readLine()) != null) {... -
hi all
how do i run dos commands from java??????????Using Runtime#exec().
Also see http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html -
Hi, I need to perform a DOS command from Java (using WFC if needed)...
I have no idea, so please help!
Thank you.OH OH OH WAIT! It is an Applet! i think there will be some security issues here! Sure enough you can't execute commands on the system from an applet unless you make some changes on the java.policy files on the client machine (that means, if your applet is in a web page, every machine which view your page).
-
Execute linux command from java
I wanna execute linux command from java, bu the output has error:
Return code = 1
top: failed tty get
The code as:
import java.io.*;
public class Execute {
public static void main(String[] args) {
try {
final Process process = Runtime.getRuntime().exec("top");
new Thread() {
public void run() {
try {
InputStream is = process.getInputStream();
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) >= 0;) {
System.out.write(buffer, 0, count);
} catch (Exception e) {
e.printStackTrace();
}.start();
new Thread() {
public void run() {
try {
InputStream is = process.getErrorStream();
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) >= 0;) {
System.err.write(buffer, 0, count);
} catch (Exception e) {
e.printStackTrace();
}.start();
int returnCode = process.waitFor();
System.out.println("Return code = " + returnCode);
} catch (Exception e) {
e.printStackTrace();
}Help please.Your code is probably good to run a program, that does not use terminal capabilities.
Program "top" is a little bit more complicated - you have to run it with a real terminal.
Try to run "xterm -e top". You can find an example how to run an external program
from java code in cnd/gdb module on http://cnd.netbeans.org
For example, take a look at openExternalProgramIOWindow() method on this page:
http://cnd.netbeans.org/source/browse/cnd/gdb/src/org/netbeans/modules/cnd/debugger/gdb/proxy/Attic/GdbProxyCL.java?rev=1.1.2.6.2.5&only_with_tag=release551_fixes&view=markup
It runs a command with external terminal.
Thanks,
Nik -
UNIX "export" Command from Java
Hi,
Am facing a problem while exeuting UNIX command from java. Am attaching the code which I am trying to execute.
import java.io.*;
public class RunCommandExample {
public static void main(String args[]) {
String s = null;
try
Runtime.getRuntime().exec("password=midware1");
//p = Runtime.getRuntime().exec("export password");
System.exit(0);
catch (IOException e)
System.out.println("[IOException]. Printing Stack Trace");
e.printStackTrace();
System.exit(-1);
}This gives me the following error.
[IOException]. Printing Stack Trace
java.io.IOException: password=midware1: not found
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:52)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at RunCommandExample.main(RunCommandExample.java:24)
Please let me know the solution for this problem.
Waiting for your valuable replay..
Thanks in advance,
Ashly.Assigning and exporting variables are not commands that you can execute from Java. You can only execute programs--binary executables. Assigning and exporting shell or environment variables is part of the shell.
Why are you trying to do this? Even if you could, it wouldn't affect the running VM, and it wouldn't affect anything outside that exec() invocation.
If you need to set them for something else you're going to run, then you should set them in a shell script and run that script. -
Unable to execute Linux command from Java
Hi,
I am currently working on a code wherein i need to execute Linux command from Java. Below are some of the query i have.
1) Is there any efficient method of running OS commands from Java, rather than using Runtime and Process method.
2) Below is details of my code which fails in execution
**-- Java Version**
java version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK Server VM (build 1.6.0-b09, mixed mode)
-- Program Code ----
Where <path> = Path i put myself
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.*;
public class GetInode{
* @param args
public static void main(String[] args) {
GetInode test = new GetInode();
test.getInode();
public void getInode(){
String command = "/usr/bin/stat -Lt <path>;
System.out.println(command);
Process process;
Runtime rt;
try{
rt = Runtime.getRuntime();
process = rt.exec(command);
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
BufferedReader bre = new BufferedReader(isr);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream());
System.out.println(bre.readLine());
System.out.println(br.readLine().split(" ")[7]);
process.destroy();
}catch (Exception ex){
System.out.println("Error :- " + ex.getMessage());
------Output -------------
/usr/bin/stat -Lt "<path>"
/usr/bin/stat: cannot stat `"<path>"': No such file or directory
Error :- null
Can any one help me what is wrong and why i am unable to run the Linux command from Java.For clarity purpose............i m submitting actual code here
--- Code ---
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.*;
public class GetInode{
* @param args
public static void main(String[] args) {
GetInode test = new GetInode();
test.getInode();
public void getInode(){
String command = "/usr/bin/stat -Lt \"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt\"";
System.out.println(command);
Process process;
Runtime rt;
try{
rt = Runtime.getRuntime();
process = rt.exec(command);
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
BufferedReader bre = new BufferedReader(isr);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
System.out.println(bre.readLine());
System.out.println(br.readLine().split(" ")[7]);
process.destroy();
}catch (Exception ex){
System.out.println("Error :- " + ex.getMessage());
--- Output ---
[ratz]s0898671: java GetInode
/usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
/usr/bin/stat: cannot stat `"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"': No such file or directory
Error :- null
-- Linux Terminal --
If i copy the first line from the output and execute on Linux terminal her is the output that i get
[ratz]s0898671: /usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt 12003 24 81a4 453166 10000 1c 360466554 2 0 1 1246638450 1246638450 1246638450 4096
Can you just assist me where am i really making mistake.......i was wondering if the command that i pass from Java....can be executed on Linux terminal why is it faling to run from java.........and when i print the Error Stream for process output........it show cannot Stat....... -
Execute unix commands from Java
Hi,
I have a client application running on windows. This client should connect to a unix server and check for the existence of a file and display the result as "File found/File not found". In order to connect from windows to the unix server, I used the sockets and the connection is successfully established. The second part is to check for the presence of the file in unix server. I searched in google.com and the option I found to execute a unix command from java is the "Runtime.exec()". Runtime.exec is considered as the less effective (not a favorable) one.
Is there any other option available (other than the Runtime) to execute the unix command from java? Can you please let me know.
Thanks a lot
AishuSo, please let me know how I can execute the above unix commands without Runtime.exec()You have a client and a server.
You want something to run on the server, not the client.
That means that something must in fact being running on the server before the client does anything at all.
For example telnet. Or a J2EE server application.
So is something like that running?
If not then there absolutely no way to do what you want, even with Runtime.exec().
If yes then what you do depends on what is running. So Runtime.exec() would be pointless if a J2EE server was running. -
How to call gnuplot command from java
Hi there,
In our course, we are required to develop an GUI for gnuplot. In case you don't know about gnuplot, it's a plotting program and has lots of command. We want to use java and swing, but now we don't know how to call gnuplot command from java, or how to execute a shell command(script) from java.
By the way, since we need read in files with several columns of data and allow user to select a column, we want to use JTable. Is that reasonable?
Thanks a lot for any suggestions!
JackHi, there:
Will using JTable add much overhead? I may have to use several JTables and switch among them. I can add scroll bar to or edit JTables, right?
BTW, do you have experience about gnuplot? Can I find the command tree of gnuplot somewhere? Or do you know a better place to post question about gnuplot? unix/linux group, maybe.
Thanks,
Jack
P.S. Would you guys answer my question after I use up my duke dollars? :- )
Maybe you are looking for
-
Adobe acrobat pro 9 help button shows no table of contents
When I open adobe acrobat pro 9 and select the help button the help window opens but there is no table of contents and if I try to search for a topic nothing happens... Any help here?
-
SAP transaction iView not executing the transaction directly
Hello guys, having a little problem with SAP transaction iView I created - specified system, where the transaction is delpoyed. When I click on the page containing the iView, R/3 logon page comes up instead of the transaction itself being executed. T
-
I want to move CS6 License to another computer
The is complex. I have a older computer that was licensed. The computer mother board failed. I repaced the mother board and now CS6 acts like it is unlicensed. On top of that I need to move the license to a newer faster computer. How do I proceed?? T
-
Urgent - JSP error in JDev 3.1 under NT 4.0
Hi, I have an error in the .jsp file(code below). I already defined the bean called FaqBean. But, from the JSP file, it can't recognize the bean. Can you please tell me what I'm doing wrong? Thanks in advance, Kaiser <%@ page import="com.taglib.wdjsp
-
Dear All, my client wish , purchase order should not go for re-release if buyer changes/ amends delivery date in ME22N Thanks