can somebody prove me the coding to update the database (mysql) with JSP

U can write all code using scriptlet. Simply start scriptlet,create connection, write and execute update query, close connection and scriptlet.
For Ex
<%
create connection
Create query
resultset
execute query
close connection
%>
Hope it provides u some help!!

U can find example code in google.

U can write all code using scriptlet. Simply start scriptlet,create connection, write and execute update query, close connection and scriptlet.
For Ex
<%
create connection
Create query
resultset
execute query
close connection
%>
Hope it provides u some help!!

U can find example code in google.

Which is, of course, exactly the wrong way to do it, reagardless of whether it works or not.

You can also scratch your back with a butcher knife, but I wouldn't suggest it.

Ya OK.
What I provided was actually the short cut.
Correct way is to do all such stuff in class. Create object in jsp and simply execute the method!!

Am I correct now??

Well, if you knew the right way, why did you suggest the wrong way?

As I said:

You can also scratch your back with a butcher knife, but I wouldn't suggest it.

Actually I wrote what came first to my mind.
Your comment stroke me to give a2nd thought.
I apologise.

the link you provided was helpful. thanks a lot.

sorry for the delay in reply..

One more help needed....

can u tel me how make a jsp page printer friendly

can somebody prove me the coding to update the database (mysql) with JSP

-----------------------html.jsp---------------------------

<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<html>
<body>
<form name="frm" method="post" action="om.jsp">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="22%">&nbsp;</td>
    <td width="78%">&nbsp;</td>
    </tr>
  <tr>
    <td>Name Student </td>
    <td> to<input type="text" name="studentName"></td>
    <td>from<input type="text" name="studentName1"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="Submit"></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>
</form>
</body>
</html>

-----------------------------om.jsp-----------------------

<html> 
<head> 
<title>result:</title> 


<%@ page import="java.io.*"%> 
<%@ page import="java.io.File"%> 
<%@ page import="java.util.*"%> 
<%@ page import="java.sql.*"%> 
<%@ page import="java.sql.Blob"%> 
<%@ page import="java.sql.PreparedStatement"%> 
<%@ page import="java.sql.BatchUpdateException"%> 
<%@ page import="javax.servlet.*"%> 
<%@ page import="javax.servlet.http.*"%> 

<% 

try 
{ 

boolean autho;

//String driver = "org.gjt.mm.mysql.Driver"; 
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
Connection con=null; 
ResultSet rs=null; 
Statement stmt=null; 


String url="jdbc:mysql://localhost:3306/om?user=root&password=omshakthi"; 

out.println("no1");
con=DriverManager.getConnection(url); 

stmt=con.createStatement(rs.TYPE_SCROLL_SENSITIVE,rs.CONCUR_UPDATABLE);


String name=request.getParameter("studentName");

String name1=request.getParameter("studentName1");

//stmt.executeUpdate("insert into om1(name) values('"+name+"')"); //insert


//stmt.executeUpdate("update om1 set name='"+name+"' WHERE name='ykuy'");//update


//name: is where u enter as get parameter
//ykuy: is some store value in mysql


//rs = stmt.executeQuery("SELECT * FROM om1"); // select all

rs = stmt.executeQuery("SELECT * FROM om1 WHERE name='"+name+"'");//use of where


if(!rs.next()) 
{
autho=false;
//out.println("not autorized");
}
else
{
autho=true;
//out.println("autorized");
}


rs = stmt.executeQuery("SELECT * FROM om1 WHERE name='"+name1+"'");


if(!rs.next()) 
{
out.println("not autorized");
}
else if(autho==false) 
{
out.println("not autorized");
}
else
{
out.println("autorized");
out.println("<h1>new mail from   "+name1+"   to   "+name+"</h1>"); 
}



/*

while (rs.next()) 
{
out.println("no2");
out.println(rs.getString("name")+"<br>");
}*/


rs.close();
}


catch (Exception e) 
{ 
out.println("no3");
//out.println("<center><font size=5> Error in inserting the data</font></center>"); 
out.println("the error is:"+e.toString()); 
} 


%> 
</body> 
</html>

@jagadesh_pesit

  1. You are just some 3 years to late with your reply
  2. You used no code tags
  3. You show database connectivity from JSP that is frown upon (bad practice)
  4. I can go on, but I rather close this thread as unproductive and sample of bad practises. You want to learn better? Then check 2 posts on the top of JSP section for more info...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.