DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JSP (http://www.daniweb.com/forums/forum24.html)
-   -   mysql+jsp (http://www.daniweb.com/forums/thread117456.html)

nireekshan Apr 4th, 2008 7:24 am
mysql+jsp
 
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();
                                                          }
               
               
       
%>

~s.o.s~ Apr 7th, 2008 10:49 pm
Re: mysql+jsp
 
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?

Sulley's Boo Apr 8th, 2008 6:49 am
Re: mysql+jsp
 
:S and, this line is missing
pst.executeUpdate();
right ppl?

*hides*

jwenting Apr 8th, 2008 1:09 pm
Re: mysql+jsp
 
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.

mr4top Apr 8th, 2008 1:44 pm
Re: mysql+jsp
 
#
String userName = "roor";
#
String password = "root";

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


All times are GMT -4. The time now is 3:59 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC