File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes connecting jsp form with db but not connecting with it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connecting jsp form with db but not connecting with it" Watch "connecting jsp form with db but not connecting with it" New topic
Author

connecting jsp form with db but not connecting with it

Omkar G. Deshmukh
Ranch Hand

Joined: Sep 21, 2012
Posts: 41
sql query--

create table empregtb
(
Reg_id varchar(30) not null default '0',
fe_name varchar(20) null,
me_name varchar(20) null,
le_name varchar(20) null,
birth_date int null default '0',
birth_month varchar(20) null,
birth_yr varchar(10) null,
e_gen varchar(10) null,
e_pan varchar(20) null,
e_login varchar(30) not null,
e_pwd varchar(20) not null,
e_quli varchar(10) null,
e_per varchar(10) null,
e_yrcom varchar(10) null,
e_exp varchar(10) null,
e_phn varchar(15) null,
e_add varchar(10) null default 'UNKNOWN',
e_pin varchar(15) null,
e_city varchar(15) null,
e_state varchar(15) null,
e_country varchar(15) null,
primary key(Reg_id)

)

jsp code-

<form name="empform" action="empregdb.jsp" method="post" >
<font size="5" color="white">
<table cellspacing="10">
<tr>
<td> First Name:     </td><td><input name="fnm" type="text" maxlength="15"></td>

</tr>

<tr>
<td>Middle Name:     </td><td><input name="mnm" type="text" maxlength="15"></td>

</tr>

<tr>
<td>Last Name:     </td><td><input name="lnm" type="text" maxlength="15"></td>

</tr>

<tr>
<td>DOB:     </td><td>Day <select name="day" id="bd_day">
<option value="-1" ></option>
<option value="01" >1</option>
<option value="02" >2</option>
<option value="03" >3</option>
<option value="04" >4</option>
<option value="05" >5</option>
<option value="06" >6</option>
<option value="07" >7</option>
<option value="08" >8</option>
<option value="09" >9</option>
<option value="10" >10</option>
<option value="11" >11</option>
<option value="12" >12</option>
<option value="13" >13</option>
<option value="14" >14</option>
<option value="15" >15</option>
<option value="16" >16</option>
<option value="17" >17</option>
<option value="18" >18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
</select>  Month <select name="month" id="bd_month">
<option value="-1" ></option>
<option value="01" >January</option>
<option value="02" >February</option>
<option value="03" >March</option>
<option value="04" >April</option>
<option value="05" >May</option>
<option value="06" >June</option>
<option value="07" >July</option>
<option value="08" >August</option>
<option value="09" >September</option>
<option value="10" >October</option>
<option value="11" >November</option>
<option value="12" >December</option>
</select>  Year <select name="yr" id="bd_yr">
<option value="-1" ></option>
<option value="1980" >1980</option>
<option value="1981" >1981</option>
<option value="1982" >1982</option>
<option value="1983" >1983</option>
<option value="1984" >1984</option>
<option value="1985" >1985</option>
<option value="1986" >1986</option>
<option value="1987" >1987</option>
<option value="1981" >1988</option>
<option value="1989" >1989</option>
<option value="1990" >1990</option>
<option value="1991" >1991</option>
<option value="1992" >1992</option>
<option value="1993" >1993</option>
<option value="1994" >1994</option>
<option value="1995" >1995</option>
<option value="1996" >1996</option>
<option value="1997" >1997</option>
<option value="1998" >1998</option>
<option value="1999" >1999</option>
<option value="2000" >2000</option>
<option value="2001" >2001</option>
<option value="2002" >2002</option>
<option value="2003" >2003</option>
<option value="2004" >2004</option>
<option value="2005" >2005</option>
<option value="2006" >2006</option>
<option value="2007" >2007</option>
<option value="2008" >2008</option>
<option value="2009" >2009</option>
</select></td>

</tr>

<tr>
<td>Gender:     </td><td><select name="gen">
<option value="-1"></option>
<option value="m">Male</option>
<option value="f">Female</option>
</select></td>
</tr>

<tr>
<td>Pan Card No:     </td><td><input name="pc_num" type="text" maxlength="20"></td>

</tr>

<tr>
<td>Login Id:     </td><td><input name="e_id" type="text" maxlength="30"></td>

</tr>

<tr>
<td>Password:     </td><td><input name="e_pwd" type="password" maxlength="20"></td>

</tr>



<tr>
<td>Qualification:     </td>
<td>
<select name="e_degree">
<option value="beit">B.E IT</option>
<option value="becomp">B.E COMP</option>
<option value="btech">B.Tech</option>
<option value="mtech">M.TECH</option>
<option value="me">M.E</option>
<option value="msc">M.Sc</option>
<option value="mca">MCA</option>
<option value="bca">BCA</option>
<option value="bsc">B.Sc</option>
<option value="phd">P.Hd</option>
</select>
</td>

</tr>

<tr>
<td>Percetage:     </td><td><input name="e_per" type="text" maxlength="8"></td>

</tr>

<tr>
<td>Year Of Completion:     </td><td><select name="yr_comp" id="cmp_yr">
<option value="-1" ></option>
<option value="1980" >1980</option>
<option value="1981" >1981</option>
<option value="1982" >1982</option>
<option value="1983" >1983</option>
<option value="1984" >1984</option>
<option value="1985" >1985</option>
<option value="1986" >1986</option>
<option value="1987" >1987</option>
<option value="1981" >1988</option>
<option value="1989" >1989</option>
<option value="1990" >1990</option>
<option value="1991" >1991</option>
<option value="1992" >1992</option>
<option value="1993" >1993</option>
<option value="1994" >1994</option>
<option value="1995" >1995</option>
<option value="1996" >1996</option>
<option value="1997" >1997</option>
<option value="1998" >1998</option>
<option value="1999" >1999</option>
<option value="2000" >2000</option>
<option value="2001" >2001</option>
<option value="2002" >2002</option>
<option value="2003" >2003</option>
<option value="2004" >2004</option>
<option value="2005" >2005</option>
<option value="2006" >2006</option>
<option value="2007" >2007</option>
<option value="2008" >2008</option>
<option value="2009" >2009</option>
<option value="2009" >2011</option>
<option value="2009" >2012</option>
<option value="2009" >2013</option>

</select></td>

</tr>

<tr>
<td>Experience:     </td><td><select name="exp" id="emp_exp">
<option value="-1" ></option>
<option value="01" >0</option>
<option value="02" >01</option>
<option value="03" >02</option>
<option value="04" >03</option>
<option value="05" >04</option>
<option value="06" >05</option>
<option value="07" >06</option>
<option value="08" >07</option>
<option value="09" >08</option>
<option value="10" >09</option>
<option value="11" >10</option>
<option value="12" >11</option>
</select> Yr</td>
</tr>

<tr>
<td>Phone No:     </td><td><input name="e_phn" type="text" maxlength="12"></td>

</tr>

<tr>
<td>Address:     </td><td><textarea cols="20" rows="4" name="add" ></textarea></td>

</tr>

<tr>
<td>Pin Code:     </td><td><input type="text" size="6" name="pin" ></td>

</tr>



<tr>
<td>City:     </td><td><select name="city">
<option value="mumbai">Mumbai</option>
<option value=" navi mumbai">Navi Mumbai</option>
<option value="pune">Pune</option>
<option value="satara">Satara</option>
<option value="nashik">Nashik</option>
<option value="solapur">Solapur</option>
<option value="kolhapur">Kolhapur</option>
<option value="bangalore">Bangalore</option>
<option value="noida">Noida</option>
<option value="ahamadabad">Ahamadabad</option>

</select></td>

</tr>

<tr>
<td>State:     </td><td><input type="text" size="20" name="state" ></td>

</tr>

<tr>
<td>Country:     </td><td><input type="text" size="20" name="country" ></td>

</tr>

<tr></tr><tr></tr><tr></tr>
<tr>
<td> <input type="submit" value="Register" style="color: orange;"></td><td> <input type="reset" value="Reset" style="color: green;"></td>

</tr>


</table>
</font>
</form>

<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>


<%
String a=request.getParameter("fnm");
String b=request.getParameter("mnm");
String c=request.getParameter("lnm");
String d=request.getParameter("day");
String e=request.getParameter("month");
String f=request.getParameter("yr");
String g=request.getParameter("gen");
String h=request.getParameter("pc_num");
String i=request.getParameter("e_id");
String j=request.getParameter("e_pwd");
String k=request.getParameter("e_degree");
String l=request.getParameter("e_per");
String m=request.getParameter("yr_comp");
String n=request.getParameter("exp");
String o=request.getParameter("e_phn");
String p=request.getParameter("add");
String q=request.getParameter("pin");
String r=request.getParameter("city");
String s=request.getParameter("state");
String t=request.getParameter("country");




Connection con=null;
PreparedStatement pst=null;
int data=0;

if(i!=null && j!=null)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
con = DriverManager.getConnection("jdbcdbc:MyNewProjectDsn");
pst=con.prepareStatement("insert into empregtb values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
pst.setString(2,a);
pst.setString(3,b);
pst.setString(4,c);
pst.setString(5,d);
pst.setString(6,e);
pst.setString(7,f);
pst.setString(8,g);
pst.setString(9,h);
pst.setString(10,i);
pst.setString(11,j);
pst.setString(12,k);
pst.setString(13,l);
pst.setString(14,m);
pst.setString(15,n);
pst.setString(16,o);
pst.setString(17,p);
pst.setString(18,q);
pst.setString(19,r);
pst.setString(20,s);
pst.setString(21,t);




data= pst.executeUpdate();


}

catch (Exception exc) {
out.println("Unable to connect to batabase.");
}
finally
{
out.close();
}
}
%>

error--

Unable to connect to batabase.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connecting jsp form with db but not connecting with it