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

Recording session value (parameter) in the bank via jsp

fabio alonso
Ranch Hand

Joined: May 15, 2010
Posts: 48

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?

Tom Reilly

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

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");;
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



I agree. Here's the link:
subject: Recording session value (parameter) in the bank via jsp