INSERT statement with JSP
Does anyone know how to create an INSERT statement with JSP using
variables??
I can do the insert if I code the values of the variables in the statement,
but when I try to use variables to do the insert it tries to insert the
variable name and not the value of the variable into the table.
Thanks,
Doug
"Doug Schaible" <[email protected]> wrote in message news:<bicO7.1279268$[email protected]>...
> I can do the insert if I code the values of the variables in the statement,
> but when I try to use variables to do the insert it tries to insert the
> variable name and not the value of the variable into the table.
Doug,
I think you missed the <%= blahblah %> syntax.
Regards
drit
Similar Messages
-
INSERT statement in JSP using variables
People,
I am having problems inserting data from JSP into a MySQL database.
For example the following works perfectly fine:
String query = "INSERT INTO `test2` (`name`, `topic`, `message`) VALUES ('Jane Doe', 'Hi there', 'Example message')";
But, however the problems take place if I try to use variable values as parameters instead of pre-defined strings.
E.g. the following (among a 100 other ways I have tried by now) does not work):
String query = "INSERT INTO `test2` (`name`) VALUES (`" + userName +"`)";
stmt.executeUpdate(query);
This did not work either:
PreparedStatement PStmt = myConn.prepareStatement("insert into (`name`) values (?)");
PStmt.setString(1, new String("`" + userName + "`"));
PStmt.executeUpdate();
I have tried without parenthesis etc. but what I pretty much get every time is:
500 Servlet Exception
java.sql.SQLException: Column not found: Unknown column 'Jane' in 'field
list'
at org.gjt.mm.mysql.MysqlIO.sendCommand(MysqlIO.java:508)
at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(MysqlIO.java:561)
at org.gjt.mm.mysql.MysqlIO.sqlQuery(MysqlIO.java:646)
at org.gjt.mm.mysql.Connection.execSQL(Connection.java:973)
at org.gjt.mm.mysql.Connection.execSQL(Connection.java:897)
at org.gjt.mm.mysql.Statement.executeUpdate(Statement.java:230)
at org.gjt.mm.mysql.jdbc2.Statement.executeUpdate(Statement.java:99)
at sql3_jsp._jspService(/sql3.jsp:49)
at com.caucho.jsp.JavaPage.service(JavaPage.java:87)
at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81)
at com.caucho.jsp.Page.service(Page.java:474)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:166)
at com.caucho.server.http.Invocation.service(Invocation.java:277)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:334)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:266)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
I do not know much about SQL or JDBC but the material I have seen makes me believe
that I am pretty much doing the right thing.
What is the right way of doing this?
I would greatly appreciate any feedback.Hi,
I think i know the problem.
Take a look on your String code :
"INSERT INTO `test2` (`name`, `topic`, `message`) VALUES ('Jane Doe', 'Hi there', 'Example message')";
it is not necessary to put QUOTE for the tablename and the fields.
my code work with :
String query = "INSERT INTO test2 VALUES( ' " + 123 + " ' ) ";
( if you inserting into all fields in your table ) OR
String query = "INSERT INTO test2 ( abc ) VALUES( ' " + 123+ " ' ) ";
( if you need to select certain fields ).
or you can try to refer to :
http://www.w3schools.com/sql/sql_insert.asp
hope this help. -
Query in Insert statement with JDBC Rx adapter
Hi,
This is a FILE to JDBC scenario.
My target datatype is like this with sample payload values
statement_s
statement_s
action='INSERT"
access
A=1234
B=1002
key
A=1234
B ="10%"
compareOperation= LIKE
A(1..1) is primary key in DB and B(0..1) colunm is an optional one.
I want to know if such kind of Insert query with(LIKE operator) is possible.
Please reply me ASAP.
Edited by: ram pranav on Feb 18, 2009 10:28 PMHi Ram,
IN case of "UPDATE_INSERT", you can use the KEY tag in your structure. Also you can provide LIKE as an attribute to the KEY element as follows :
<key1>
<col4 compareOperation=u201DLIKEu201D>val%</col4>
</key1>
But when you are trying to insert the data_, the <key> tags will be ignored and only <access> will be considered._
action=UPDATE_INSERT
The statement has the same format as for the UPDATE action. Initially, the same action is executed as for UPDATE. If no update to the database table can be made for this action (the condition does not apply to any table entry), values of the table described in the <access> element are inserted in accordance with the description of the action INSERT. <key> elements are ignored in this case.
The response document has the following format; one of the two values is always 0 because either an UPDATE or an INSERT action is always executed:
Go through the link I have provided earlier.
Thanks,
Pooja Pandey -
I am having a problem. I would like to insert some form data into a database using jsp but I have coded it and it gives me an error insert statement syntax is incorrect here is my code
<%@page import="java.sql.*"%>
<html>
<head>
<title>
</title>
</head>
<body>
<%
String _driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String _url = "jdbc:odbc:testdata";
try {
Class.forName (_driver);
String dataSourceName = _url;
String dbURL = dataSourceName;
Connection con = DriverManager.getConnection(dbURL);
Statement s = con.createStatement();
String insert;
insert = "insert into order (field1 , field2 , field3) values ('"
+ request.getParameter("item1") + "' , '" + request.getParameter("item2") + "' , "
+ "'" + request.getParameter("item3") + "')";
out.print(insert);
s.execute(insert);
s.close();
con.close();
} // closes try statement
catch (Exception err) {
out.print("ERROR: " + err);
}; // closes catch statement
%>
<a href="shoppingcart.jsp">go back to shopping cart</a>
</body>
</html>here is the error it gives me
ERROR: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
the insert statement looks right to me but there is something wrong anyone got any ideas. Thanxs in advance.AAAHHHH. Order is a reserved word and that was what my table was named. I suppose because of the order by clause it is. Figures spend hours staring at it and it is right there. I have to start using prefixes and suffixes on my code it would save me so much hassel.
-
Insert statement with Date, time into Oracle
Hi,
I've got the following statement that I'm trying to insert into Oracle. Actually had to change up the format to dd-mm-yy to get it to insert the date correctly, not sure why, but I've got it "supposedly" formatted to also insert the hours, min., seconds into the db record, but it's not catching it.
My code:
INSERT INTO VOTETBL
(CHANGE_CTRL_ID,BUSVP,BRANCH,VOTE,VOTE_TIMESTAMP)
VALUES (?, ?,?,?,to_date(sysdate, 'dd-mm-yy hh24:mi:ss'));Shouldn't the sysdate capture all those elements sufficiently? The day, month, year get inserted correctly with this, but not so for the time portion.
Any suggestions is welcomed.
Thx.ok, thanks.
I tried making a result set with the following:
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rst = stmt.executeQuery("select to_char(sysdate) from dual");
Date dualtimestamp = (rst.getDate("sysdate"));But it makes the servlet blow up! Not sure why either, because if I enter that exact statement in Oracle, it pulls back the date and time just like I aim to. But not embedded in the result set statement within the servlet.
It breaks up somehow and doesn't get that result! -
Insert statement with timezone asking for parameter
I have an insert statement in a file.
When the whole file is executed it inserts around 300 rows in to table.
One of the insert statement is failing. This insert statement inserts a query into column of a table.
It is as following
Insert into hr.TABLE_PATH
(PATH, TABLE_OWNER_NAME, TABLE_NAME, PATH_NAME, TABLE_ACCESS_PATH_DESC, TABLE_PATH_SQL_TXT, PROCESS_CODE, DELETE_IND, ACCESS_ID)
Values
(290, HR, EMPLOYEES, 'Reconc', 'XYZ', 'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )', 'N ', 'N', 2);
The problem is with this piece of insert:
TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp
: --> is being considered as parameter.
Where as the whole sql thing needs to get inserted into the table.If you are inserting a string, then any quotes inside the string should be replaced with two single quotes,
try this,
INSERT INTO hr.TABLE_PATH (PATH,
TABLE_OWNER_NAME,
TABLE_NAME,
PATH_NAME,
TABLE_ACCESS_PATH_DESC,
TABLE_PATH_SQL_TXT,
PROCESS_CODE,
DELETE_IND,
ACCESS_ID)
VALUES (
290,
HR,
EMPLOYEES,
'Reconc',
'XYZ',
'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )',
'N ',
'N',
2
);Note the
TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp First off, How are you inserting the data? using sqlldr or utl_file?
If you are inseting using a script from Sqlplus
use
SET DEFINE OFFjust to make sure nothing is treated as a parameter.
G.
Edited by: Ganesh Srivatsav on Apr 6, 2011 5:20 PM -
Insert statement with loop function
Hello all,
I'm new with the loop function
What need to do is to use a select statement with a condition
This output needs to be inserted in a table
The values of the condition are stored also in a table
It will be something like this:
BEGIN
FOR i IN (select nrs from table1) LOOP
INSERT INTO table_out_loop
SELECT * FROM bigtable_vw
WHERE nr = i
END LOOP ;
END ;
I cant use a direct insert_into function in this case so I need the plsql to 'look' for the values 1 by 1 from the table1
Any help would be appreciatedCan't you just:
insert into table_out_loop
select *
from bigtable_vw
where nr in (select nrs from table1);
If not, then post a better example and/or rephrase the question... -
Creating Multiple INSERT statements with SQL
is there a way to create multiple INSERT staements with SQL .
Example scenario : This is only example but i have lot of data in the real time.
sql : Select Emplid from Table A where Emplid between 100 and 350 will retun me 50 rows . i want to insert those rows into another table.
I am looking for output like below instead of Giving output just as EMPLIDs
Insert into PS_LM_DATA ( EMPLID ) values ( 123 )
Insert into PS_LM_DATA ( EMPLID ) values ( 234 )
Insert into PS_LM_DATA ( EMPLID ) values ( 334 )
and so on....
thanks ,
KaruIf you are inserting into another table, you could use
insert into PS_LM_DATA ( EMPLID )
select Emplid from Table A where Emplid between 100 and 350Example:
SQL> insert into emp2(empno) select empno from emp;
14 rows created.
SQL> insert into emp2(empno) select empno from emp where empno between 7369 and 7788;
8 rows created. -
Error Running SQL Insert Statement with & in it
Eclipse: 3.5 Galileo on Window Vista
OEPE: 11gR1 11.1.14
I get "invalid character" error when running this query in Eclipse:
INSERT INTO RECIPE (recipeId, name1, name2, recipeCategoryId) VALUES (2, 'Chunky Chicken Egg Rolls', 'No take–out joint can compare!', 1);
I've tried multiple ways trying to escape the & character, but nothing worked. What is the right way of executing SLQ via OEPE plugin that have special characters in them.
FYI, the following worked fine in Oracle 10g iSQL*Plus:
SET DEFINE ~;
INSERT INTO RECIPE (recipeId, name1, name2, recipeCategoryId) VALUES (2, 'Chunky Chicken Egg Rolls', 'No take–out joint can compare!', 1);
Thanks,
Dmitri.Very interesting case. I tried your insert stmt and got the same error. I finally got it to work by removing the ";" in the end. It looks like the jdbc driver choked up while there is ";" in the middle of the pl/sql statement and ";" in the end. If you remove ";" in the "No take–out joint can compare!" string and leave the ";" in the end, it also works!
I don't quite understand why Oracle JDBC dirver behaves like that. I'll investigate it more and we may need to do some preprocessing on the pl/sql statement before sending it to the driver. At the mean time, just remove the ";" in the end if your string literal contains ";".
Please let me know whether this workaround works for you. Thanks!
Shenxue -
I'm trying to insert Data into an access table. Moreover, I'm able to retrieve data on the table (to prove that I'm connecting fine)... I just can't insert Data
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url);
System.out.println("Connection Successful");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("INSERT INTO Worker VALUES ('" + strDataName + "', '" + strDataDept + "', '" + dblDataHoursWrked + "', '" + dblDataHourlyWage + "', '" + dblDataPay + "')");
rs.close();
processQuery(con, st); // does what is nessesary to complete the current request
st.close();
con.close();
catch (ClassNotFoundException e)
System.out.println("failed to load OBCD driver. ");
System.out.println ("Class errros: " + e);
}For some reason, I don't have any errors Its just not inserting the data to the table.. any help would be greatly appreciatedtry
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url);
System.out.println("Connection Successful");
Statement st = con.createStatement();
//ResultSet rs = st.executeQuery("SELECT INTO Worker VALUES ('" + strDataName + "', '" + strDataDept + "', '" + dblDataHoursWrked + "', '" + dblDataHourlyWage + "', '" + dblDataPay + "')");
Here use update query "executeUpdate("UPDATE TABLENAME SET COLUMN=VALUE,.........................WHERE CANDITION );
rs.close();
processQuery(con, st); // does what is nessesary to complete the current request
st.close();
con.close();
catch (ClassNotFoundException e)
System.out.println("failed to load OBCD driver. ");
System.out.println ("Class errros: " + e);
U CHECK IT ,I THINK IT WILL WORK -
Insert statement with using the value in struct
Would like to clarify, i use cursor for selecting data from tableA and fetch the cusor into a struct. So the struct is holding all my data then i would like to insert all this data into tableB. Can i direct insert the data with the stuct?
eg: INSERT INTO tableB VALUES (:mystruct);See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#i20479
chapter Inserting PL/SQL Records into the Database
BTW Update you should use cautiously, not to update all PKses and FKses see http://www.oracle-developer.net/display.php?id=418 for some examples.
Gints Plivna
http://www.gplivna.eu -
QUESTION ON INSERT STATEMENT WITH SELECT
Hi
I have a table which contains three fields
Table name : USERS
ID NUMBER(10),
NAME VARCHAR2(50),
EMAIL VARCHAR2(50)
SEQUENCE by name SEQ_ID
I am trying to insert values into USERS from EMPLOYEE by virtue
of insert into USERS (SELECT NAME, MAIL from EMPLOYEE) but i
want to have one id for all the rows fetched from my inner
query.
I would like to know if here is a way, by which i can fetch a
constant in my select statement which is not present in the
table and use it like
insert into USERS ( SELECT constant, NAME, MAIL FROM EMPLOYEE );
where constant is some number unique for a given insertion.
Thanks
ArunWhy not just try it? All you had to do was type
insert into USERS SELECT 1, NAME, MAIL FROM EMPLOYEE ;
and you would have had your answer immediately instead of
waiting for me to tell you.
rgds, APC -
Insert Statement with Where Clause
I m using this but giving error "Encounter the Symbol "Where" when expecting one of the following.
Code is :-
insert into dum (cost_no, c_size, cmt1, cmt2, cmt3)
values (:sizecost.cost_no, :sizecost.c_size, :bottomcost.cmt1, :bottomcost.cmt2, :bottomcost.cmt3)
where :sizecost.cost_no := :costmain.cost_no;Something like this ?
insert into dum (cost_no, c_size, cmt1, cmt2, cmt3)
select :sizecost.cost_no, :sizecost.c_size, :bottomcost.cmt1, :bottomcost.cmt2, :bottomcost.cmt3
from dual
where :sizecost.cost_no := :costmain.cost_no;Nicolas.
: all these are items on form Ok, why not try to use the Form Forum ?
Message was edited by:
N. Gasparotto -
Insert statement with subquery to insert multiple rows
Hi frnds,
Kindly find the below mentioned query and error. Also suggest me to go ahead.
SQL> INSERT INTO FM_TRAN_DOC_NO (TDOC_COMP_CODE,
2 TDOC_TRAN_CODE,
3 TDOC_ACNT_YEAR,
4 TDOC_CUR_NO,
5 TDOC_MAX_NO,
6 TDOC_CAL_YEAR,
7 TDOC_PERIOD,
8 TDOC_DIVN_CODE,
9 TDOC_DEPT_CODE,
10 TDOC_CR_UID,
11 TDOC_CR_DT,
12 TDOC_UPD_UID,
13 TDOC_UPD_DT)
14 SELECT '001',
15 (SELECT DISTINCT TDOC_TRAN_CODE FROM FM_TRAN_DOC_NO
16 '6',
17 '0',
18 '9999',
19 NULL,
20 NULL,
21 NULL,
22 NULL,
23 'AGT',
24 TO_DATE (SYSDATE),
25 NULL,
26 TO_DATE (SYSDATE) FROM DUAL;
(SELECT DISTINCT TDOC_TRAN_CODE FROM FM_TRAN_DOC_NO ),
ERROR at line 15:
ORA-01427: single-row subquery returns more than one rowThis "SELECT DISTINCT TDOC_TRAN_CODE FROM FM_TRAN_DOC_NO" query returns multiple rows. So what is your requirement?
Try the below insert if you want to select from tale FM_TRAN_DOC_NO
INSERT INTO FM_TRAN_DOC_NO (TDOC_TRAN_CODE,
TDOC_COMP_CODE,
TDOC_ACNT_YEAR,
TDOC_CUR_NO,
TDOC_MAX_NO,
TDOC_CAL_YEAR,
TDOC_PERIOD,
TDOC_DIVN_CODE,
TDOC_DEPT_CODE,
TDOC_CR_UID,
TDOC_CR_DT,
TDOC_UPD_UID,
TDOC_UPD_DT)
SELECT DISTINCT
TDOC_TRAN_CODE
'001',
'6',
'0',
'9999',
NULL,
NULL,
NULL,
NULL,
'AGT',
TO_DATE (SYSDATE),
NULL,
TO_DATE (SYSDATE) FROM TDOC_TRAN_CODE;
Message was edited by: 000000 -
Please i need help on how to enter multiple row into mysql with one insert
statement and jsp , i have been trying this for weeks without sucess e.g
<---- THIS AN EXAMPLE OF MY INSERT FORM ---->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="some sort of jsp page">
mike : <input type="text" name="staffid" />
john : <input type="text" name="staffid" />
peter :<input type="text" name="staffid" />
james :<input type="text" name="staffid" />
jerry :<input type="text" name="staffid" />
mikel: <input type="text" name="staffid" />
<input name="submit" type="button" />
</form>
</body>
</html>
<--MY DATABASE LOOKS LIKE --->
name | staffid |
| |
| |
| |
I have been looking for a way to enter only the value or all the values that is entered by
the user.ODAFEONIHOWO wrote:
Please i need help on how to enter multiple row into mysql with one insert
statement and jsp it's not possible - you'll need to do a batch insert
i have been trying this for weeks without sucess e.g how much experience do you have with Java?
Maybe you are looking for
-
I need to put my iphone into recovery mode so i can restore it, but i cant turn the iphone off to do this, help please!!
-
Free space in Home Folder???
I have been away on holiday and have now come back to the following message when using Mail on my computer: *You must free up space in your home folder before using Mail. Delete unneeded documents or move documents to another volume.* It then closes
-
How can I group emails by sort and thread at the sametime?
I like emails sorted by date. I know when threaded the dates are all mixed up. Yet, outlook allows me to do this and it is very convenient.
-
I need to add personnel area, personnel sub area, emp group and sub group field in 'Selection fields from infoset' section in SQ01/02 adhoc query so that user can execute query for these fields as a selection. How to do it.
-
Cost variance for the material master
Hi all, This is very urgent requirement. How to maintain cost variance for the material master? I will assign the points venu