Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DB insert using JSP

 
Bob Kimmel
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm fairly new with Programming and I'm trying to write a JSP
that will do an insert into Oracle. I found some example code
but I'm getting some errors I don't understand. Here is my
JSP and HTML form looks like:
JSP
<%@ page language="java"
contentType="text/html" %>
<%@ page import = "java.sql.*" %>

<%
String PROJECT_ID = request.getParameter("PROJECT_ID");
String PRODUCT_NAME = request.getParameter("PRODUCT_NAME");
String KICKOFF_DATE = request.getParameter("KICKOFF_DATE");


Class.forName("oracle.jdbc.driver.OracleDriver");
String connection_string = "jdbc racle:thin:@52796e:1521:ccevs";
String username = "CCEVS_RECORDS_KEEPING_SYSTEM";
String password = "ccevs";
Connection conn = DriverManager.
getConnection(connection_string,
username, password);
Statement stmt = conn.
createStatement();

String sql = "INSERT INTO CCEVS_PROJECTS_REGISTRY" +
"VALUES('" + PROJECT_ID + "', " +
"'" + PRODUCT_NAME + "', " +
"'" + KICKOFF_DATE + "') ";
/*
* Send the SQL to the database.
*/
stmt.executeUpdate(sql);
%>
<HTML>
<HEAD>
<TITLE>
New Person: <%= PROJECT_ID + " " + PRODUCT_NAME %>
</TITLE>
</HEAD>
<BODY>

I added <%=PROJECT_ID + " " + PRODUCT_NAME %> to the database. Here is
the complete list of people:

<TABLE BORDER>
<TH>PRODUCT_NAME</TH> <TR> </TR>PROJECT_ID</TH>

<%
ResultSet rs =
stmt.executeQuery("SELECT * FROM CCEVS_PROJECTS_REGISTRY");
while(rs.next()) {
PROJECT_ID= rs.getString(1);
PRODUCT_NAME = rs.getString(2);
KICKOFF_DATE = rs.getString(3);
%>

<TR>
<TD><%= PROJECT_ID + " " + PRODUCT_NAME %></TD>
<TD><%= KICKOFF_DATE %></TD>
</TR>

<% }
/* end of the while loop */
%>

</TABLE>
</BODY>
</HTML>
------------------------------------------------------------------
HTML Form
<HTML>
<HEAD>
<TITLE>Add a New Person</TITLE>
</HEAD>
<BODY>
<FORM ACTION="insert.jsp">
<TABLE>
<TR>
<TD>PRODUCT_NAME:</TD>
<TD><INPUT TYPE="text" NAME="PRODUCT_NAME"></TD>
</TR>
<TR>
<TD>PROJECT_ID:</TD>
<TD><INPUT TYPE="text" NAME="PROJECT_ID"></TD>
</TR>
<TR>
<TD>KICKOFF_DATE:</TD>
<TD><INPUT TYPE="text" NAME="KICKOFF_DATE"></TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="RIGHT">
<INPUT TYPE="submit" VALUE="Add Product">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
I get a couple errors but the first one is:
java.sql.SQLException: ORA-00928: missing SELECT keyword.
I don't see anything wrong wth The Select Statement, any
ideas/suggestions.
Thanks,
Bob
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be careful when you have multi-line strings:
String sql = "INSERT INTO CCEVS_PROJECTS_REGISTRY" +
"VALUES('" + PROJECT_ID + "', " +
"'" + PRODUCT_NAME + "', " +
"'" + KICKOFF_DATE + "') ";
You need to insert spaces in the proper spots so the words do not run together and confuse oracle -- CCEVS_PROJECTS_REGISTRYVALUES(....
I'm not sure if this is causing the error message, but you might want to fix this nonetheless.
WS
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!