Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Server Insertion to DB

Description: This is a simple code that add a UserName and PassWord to a table "Access" through ODC connection.
1.First I created the HTML form with two fields with an action that sends the data to the "AddUserDbd.jsp" ...
2. "AddUserDbd.jsp" initialize the connection and two functions "OpenConnection" and "InsertUsers(,,)"
3. getParameter is used to read the fields from ny HTML form e.g
Name = request.getParameter("userName"); Password = request.getParameter("passWord");
and both Paramenters are then iserted into the function InsertUsers(Name,Password);
see the code to understand ..




-------------------- HTML form -------------------------------------





AddUser.jsp














UserName:
Password:





-----------------------------------------------------------------------------------



AddUserDbd.jsp ----------- Processing File --------------

<%@ page import = "java.sql.*"%>



AddUserDbd.jsp

<%! String url ="jdbc:odbc:monthly";
Connection conn;
Statement stmt;
String Name,Password = "";
int Level;
String SQL;


public void OpenConnection()
{

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
System.out.println(e.toString());

}
try
{
conn = DriverManager.getConnection(url,"sa","");
}
catch(Exception e)
{
System.out.println("Could not load Driver");

}

} // end Openconnection

public void InsertUsers(String UserName,String Passwd,int Level)
{
try
{
stmt = conn.createStatement(); //connect the statement to the connection


SQL ="insert into Access(UserName,Password,AdminLevel) values('" + UserName + "','" + Passwd + "'," + Level + ")";
stmt.executeUpdate(SQL);

}

catch(SQLException ee)
{
System.out.println(ee);

}

} //end InsertUsers
%>
<%
OpenConnection();

Name = request.getParameter("userName");
Password = request.getParameter("passWord");

InsertUsers(Name,Password,1);

out.println(SQL);

conn.close();
stmt.close();
%>

Place AddUserDbd.jsp's content here




No comments: