File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Inserting form data into database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Inserting form data into database?" Watch "Inserting form data into database?" New topic
Author

Inserting form data into database?

Kameswari Jyosyula
Ranch Hand

Joined: Feb 20, 2001
Posts: 39
Hi all, i am trying to call the bean's method that inserts data into database but get an error "Invalid expression statement.
String int = insertBean.recordIssues();
';' expected."
The ; is there.
I don't understand how to call the bean's method.If i remove that statement then i can see the jsp page (thats supposed to show the data) without any data.
Someone plz help.
Here's the code for the jsp and the bean:
<%@ page errorPage="Exception.jsp" %>
<jsp:useBean id="sessionManager" class="SessionManager" scope="application" />
<jsp:useBean id="credentials" class="UserCredentials" scope="session" />
<jsp:useBean id="insertBean" class="InsertManager" scope="request" >
<jsp:setProperty name="insertBean" property="*" />
</jsp:useBean>
<% String int = insertBean.recordIssues(); %>

<html>
<body text="#000000" bgcolor="#e0e0e0">
<font face = "Arial, Helvetica" size="+1">
<center>
Welcome,
<%= credentials.getUser() %> !!
<br>
<br>
</center>
</font>
<br>
<br>
We have recorded the following data in issues.
<br>
<br>
Database = <jsp:getProperty name="insertBean" property="database" />
<br>
Title = <jsp:getProperty name="insertBean" property="title" />
<br>
Description = <jsp:getProperty name="insertBean" property="description" />
<br>
Action = <jsp:getProperty name="insertBean" property="action" />
<br>
Status = <jsp:getProperty name="insertBean" property="status" />
<br>
Created Date = <jsp:getProperty name="insertBean" property="create_date" />
<br>
Status Date = <jsp:getProperty name="insertBean" property="status_date" />
<br>
</body>
</html>
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javaservlets.jdbc.ConnectionPool;
public class InsertManager {
private Hashtable currentLogins;
private ConnectionPool connectionPool;
private static final int TIMEOUT_MINUTES = 5;
private static final long ONE_MINUTE = 60000L;
private static final String POOL_CFG_FILE =
"javaservlets/jdbc/InsertManagerConnectionPool.cfg";
private String database = "";
private String title = "";
private String description = "";
private String action = "";
private String status = "";
private String create_date = "";
private String status_date = "";

// private static final String UPDATE_ACCOUNT_STATUS =
//"UPDATE idpassword SET status = 0 WHERE userid = ";

private static final String INSERT_ISSUES =
"INSERT INTO issues" +
"(db_id,issues_id,issue,short_desc,action,status,create_date,status_date) VALUES (";
private static final String RPAREN = ")";
private static final String COMMA = ",";
private static final String QUOTE = "'";


public InsertManager() throws Exception {
connectionPool = new ConnectionPool();
connectionPool.initialize(POOL_CFG_FILE);
currentLogins = new Hashtable();

}

public String recordIssues()
throws SQLException {
Connection conn = connectionPool.getConnection();

String database = getDatabase();
String title = getTitle();
String description = getDescription();
String action = getAction();
String status = getStatus();
String create_date = getCreate_date();
String status_date = getStatus_date();
Statement us = conn.createStatement();

//java.util.Date dt = new java.util.Date();
//SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd");
// String fd = sdfd.format(dt);
// SimpleDateFormat sdft = new SimpleDateFormat("HH:mm:ss");
// String ft = sdft.format(dt);


int stmtInt = us.executeUpdate( INSERT_ISSUES +
QUOTE +database + QUOTE + COMMA +
QUOTE + title + QUOTE + COMMA +
QUOTE + description + QUOTE + COMMA +
QUOTE + action + QUOTE + COMMA +
QUOTE + status + QUOTE + COMMA +
"to_date(" + QUOTE + create_date + QUOTE + COMMA + QUOTE + "yyyy-MM-dd " + QUOTE + RPAREN + COMMA +
"to_date(" + QUOTE + status_date + QUOTE + COMMA + QUOTE + "HH24:MI:SS" + QUOTE + RPAREN );
connectionPool.close(conn);
return "Inserted row " + stmtInt;
}

public String getDatabase( ) {
return database;
}
public void setDatabase( String database ) {
this.database = database;
}
public String getTitle( ) {
return title;
}
public void setTitle( String title ) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}

public String getAction( ) {
return action;
}
public void setAction( String action ) {
this.action = action;
}
public String getStatus( ) {
return status;
}
public void setStatus( String status ) {
this.status = status;
}
public String getCreate_date( ) {
return create_date;
}
public void setCreate_date( String create_date ) {
this.create_date = create_date;
}
public String getStatus_date( ) {
return status_date;
}
public void setStatus_date( String status_date ) {
this.status_date=status_date;
}

}
Thank you
Kameswari Jyosyula
Ranch Hand

Joined: Feb 20, 2001
Posts: 39
I solved that problem : I changed the following line:
<% String int = insertBean.recordIssues(); %>
to
<% String insert = insertBean.recordIssues(); %>
Its working.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

<% String int = insertBean.recordIssues(); %>
Just curious, Do you use an IDE?
That should have highlighted that int is a keyword
in Java.
Good spotting.
Also, when you post source code, please use [ code ] tags.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Kameswari Jyosyula
Ranch Hand

Joined: Feb 20, 2001
Posts: 39
No, I don't use an IDE
And yes! I shall use the tags next time.
Originally posted by Madhav Lakkapragada:

<% String [b]int
= insertBean.recordIssues(); %>
Just curious, Do you use an IDE?
That should have highlighted that int is a keyword
in Java.
Good spotting.
Also, when you post source code, please use [ code ] tags.
- satya[/B]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting form data into database?