Please take a look at for this jsp coding. here i can successfully insert the client details to the table. Only after inserting successfully i need to run another query.This will get the userID from the table.(Auto_Increment value).
<%@ page language="java" import="java.sql.*" %>
<%
String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try
{
String url="jdbc:mysql://localhost/my_db?user=root&password=dba";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
if(request.getParameter("action") != null)
{
String name=request.getParameter("c_name");
String email=request.getParameter("c_email");
String username=request.getParameter("c_username");
stmt.executeUpdate("insert into clients(c_name,c_email,c_username) values('"+name+"','"+email+"','"+username+"')");
/*
If client inserted succesfully I need to Get the client id from the Table for that client
I can do the SQL part but, How could i find out the insertion happend or not. i need to build up a condition here but how.
*/
}else
{
out.println("<font face=\"verdana\" size=\"2\" color=\"red\"><b> UnAuthorized Access !</b></font>");
}
%>
CREATE TABLE `clients` (
`c_id` int(11) NOT NULL auto_increment,
`c_name` varchar(50) NOT NULL,
`c_email` varchar(100) NOT NULL,
`c_username` varchar(25) NOT NULL,
`c_password` varchar(25) NOT NULL default '0',
PRIMARY KEY (`c_id`),
UNIQUE KEY `c_username` (`c_username`)
)