Jsp Program to Install a Database

Only available on StudyMode
  • Topic: User, Login
  • Pages : 11 (1626 words )
  • Download(s) : 8
  • Published : February 28, 2013
Open Document
Text Preview
Experiment-9
Aim: Install a database(Mysql or oracle) Create a table which should contain atleast the following fields : name,password.Practice JDBC Connectivity.Write a java program /servlet/JSP to connect to that database and extract data from the tables and display them. Copy the below path to CLASSPATH C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar create database db; use db; create table login(username varchar(10),password varchar(10)); Reg.html

<html>
<head>
<title>userlogin</title>
</head>
<body>
<h2>Registratin form</h2>
<form action="http://localhost:8080/jsp2/one.jsp" method="get">
username:<input type="text" name="user">
Password:<input type="password" name="pwd">
<input type=submit value="register">
</body>
</html>
one.jsp
<%@ page import="java.sql.*,java.io.*" %>
<html>
<body>
<%
String username=request.getParameter("user");
String password=request.getParameter("pwd");
java.sql.Connection con=null;
String url="jdbc:mysql://localhost:3306/";
String dbase="db";
String driver="org.gjt.mm.mysql.Driver";
String user="root";
String pass="root";
try
{
Class.forName(driver).newInstance();
con=DriverManager.getConnection(url+dbase,user,pass);
try{
Statement st=con.createStatement();
st.executeUpdate("INSERT login values("+"'username'"+","+"'password'"+")");
System.out.println("1 row effected");
out.println("Inserted");
}
catch(SQLException s)
{
System.out.println("not inserted");
}
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<a href="http://localhost:8080/jsp2/two.jsp">List users</a> </body>
</html>
two.jsp
<%@ page import="java.sql.*,java.io.*" %>
<html>
<body>
<%
java.sql.Connection con=null;
String url="jdbc:mysql://localhost:3306/";
String dbase="db";
String driver="org.gjt.mm.mysql.Driver";
String user="root";
String pass="root";
Class.forName(driver).newInstance();
con=DriverManager.getConnection(url+dbase,user,pass);
Statement st=con.createStatement();
ResultSet res=st.executeQuery("SELECT * FROM login1");
out.println("username"+"\t"+"password");
while(res.next())
{
String s=res.getString("username");
String s1=res.getString("password");
out.println(s+"\t"+s1);
}
con.close();
%>
</body>
</html>
Experiment-10
Aim: Write a jsp which does the following job.Insert the details of the 3 or 4 users who register with the website by using registration form.Authenticate the user when he submits the login form using the username password from the database. Same as above programs.

Experiment : 11
AIM: Create tables in the database which contain the details of items like Book name, Price, Quantity, Amount of each category. Create the catalogue page in such a way that it should connect to the database and extract data from the tables and display them in the catalogue page using JDBC. CREATING THE TABLE

Create table BookInfo(name varchar(10),author varchar(10),publication varchar(10),ISBN integer,edition integer,price integer); insert Bookinfo values(‘cds’,’balaguruswamy’,’sure’,64737,3,550); Cart.jsp

<%@ page import="java.sql.*,java.io.*" %>
<html>
<body>
<%
java.sql.Connection con=null;
String...
tracking img