• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Recording session value (parameter) in the bank via jsp

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

...
%>

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!