0

i'm making a web application based on jsp
i wan't a code that when a button clicked, take value from textbox and insert its value into mysql database pool maybe the sql stmt only isn't right
my code is:

<form id="form1" name="form1" method="post" action="http://localhost:8080/servlet/mailservlet">
                      <p>&nbsp;</p>
                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="88%">&nbsp;&nbsp;<textarea name="txtarea_Post_Wall" id="txtarea_Post_Wall" cols="45" rows="2"></textarea></td>
                          <td width="12%"><strong>
                            <input type="submit" name="btn_Post_Wall" id="btn_Post_Wall" value="Post" />
                            
		
		
	<% 
	Connection con = null;
	Statement stmt = null;


    try {
    	Context initContext = new InitialContext();
		Context envContext  = (Context)initContext.lookup("java:comp/env");
    	DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource");
		System.out.println("Got DataSource: " +ds.toString() );
		con = ds.getConnection();
		System.out.println("Got Connection: " +con.toString() +"\n");
	
	
		} catch(java.lang.Exception e) {
			e.printStackTrace();
			System.err.print(e.getClass().getName());
			System.err.println(e.getMessage());
		}
		try {
	        stmt = con.createStatement();	
	        String tet=(String) session.getAttribute("txtarea_Post_Wall2");
		ResultSet rs = stmt.executeQuery("INSERT INTO wall (text, ID, author) VALUES ('" + tet + "' , 1 , dfdf)");
		
		System.out.println("inserted");
			
		
			
		
		
		
		
		rs.close();
		stmt.close();
		con.close();
		}
		catch(java.lang.Exception e) {
			e.printStackTrace();
			System.err.print(e.getClass().getName());
			System.err.println(e.getMessage());
		
		
		
		}
		%>
                          </strong></td>
                        </tr>
                        <tr>
                          <td>&nbsp;&nbsp; Max. 1000 Characters </td>
                          <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td height="21">&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                      </table>
                      <p>&nbsp; </p>
                    </form></td>

plz answer me

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by peter_budo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.