hai
i am nireekshan
i am using mySql database in this i am create employe table
Now i am davalep One .HTML Page in this i am write the employe table fieldes-----------And write Jsp page inThis i write MYSQL CONNection code And Insert Prapared Staments
Now i am run TOMCat 5.0 Server,open .HTML page INSERT EMploye Fied Values Submet ok
next Work is Down NOT store data in database
plse see my program tell me any ERROR plse ...............
HTML..............>jsp.................;

<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.io.*" %>

<%@ page import="java.sql.*" %>
<% 
  
	String vemp_code=request.getParameter("emp_code");
	String vemp_name=request.getParameter("emp_name");

Connection conn = null;
ResultSet rs=null;
String url = "jdbc:mysql://localhost:3306/";
String driverName = "com.mysql.jdbc.Driver";
String userName = "roor";
String password = "root";
		try{
			Class.forName(driverName).newInstance();	
			conn = DriverManager.getConnection("jdbc:mysql://localhost/niree",userName,password);
			Statement stmt = conn.createStatement();
			stmt.executeUpdate("use newuser;");
			 out.println(" connection is established");
 
	//Statement stmt = conn.createStatement();
  	//int val = //stmt.executeUpdate("INSERT employe VALUES(?,?)"); 
			PreparedStatement pst;				
			pst=conn.prepareStatement(" insert into employe values(?,?)");
			pst.setString(1,vemp_code);
			pst.setString(2,vemp_name);
					}   
			  catch(Exception e){
		      System.out.println("error occured");
		        e.printStackTrace();
							   }
		
		
	
%>

Don't write database connectivity code in a JSP; that's not what JSP's were meant for. Push all that database logic inside a servlet. Use JSP only as a presentation technology.

And BTW, have you hosted your files on the Tomcat server? What is the URL you are using to access your HTML? What kind of error do you get? Aren't the error logs useful?

I wouldn't know. As soon as I see a tag starting a scriptlet I quit reading and give the canned answer to not use Java code in JSP.

#
String userName = "roor";
#
String password = "root";

i think you should take care of Name
check it plase it should be ROOT not ROOR

This article has been dead for over six months. Start a new discussion instead.