Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

execute multiple queries in JSP+MySQL

843838Mar 29 2007 — edited Mar 29 2007
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`)
) 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2007
Added on Mar 29 2007
7 comments
277 views