• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recording session value (parameter) in the bank via jsp

 
fabio alonso
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%

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

...
%>

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic