aspose file tools*
The moose likes JDBC and the fly likes Recording session value (parameter) in the bank via jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Recording session value (parameter) in the bank via jsp" Watch "Recording session value (parameter) in the bank via jsp" New topic
Author

Recording session value (parameter) in the bank via jsp

fabio alonso
Ranch Hand

Joined: May 15, 2010
Posts: 48
Hi,

I know thatit is not a good practice ,but for sake of testing .

I'm trying to send a value of a parameter to my bank via JSP. I can retrieve the session value (parameter)

The code below works, but he did not write value to database.





anybody help?

thanks
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Do you know whether the value of fonte is correct and that it exists in column id of a row in table pedido? The statement stmt1.executeUpdate() returns a value. What is that value?
wilson marasigan
Greenhorn

Joined: Dec 24, 2010
Posts: 4
%

String idOrigem = (String)session.getAttribute( "fonte" );
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company3", "test3", "password3");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT origem FROM register WHERE origem = " + idOrigem + " ORDER BY id Desc LIMIT 1");
rs.next();
String fonte = rs.getString("origem"); // <--name field of database
if ( idOrigem != null && !rs.wasNull() ){

// creating Query String
String query = "update pedido set origem = ? where id = ?";

// Creating Statement for query execution
PreparedStatement stmt1 = conn.prepareStatement(query);

stmt1.setString(1, idOrigem);
stmt1.setString(2, fonte);

// Updating Table
stmt1.executeUpdate();

stmt1.close();
conn.close();
}
rs.close();
stmt.close();

...
%>

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Recording session value (parameter) in the bank via jsp