Access Modifiers 2 – Static,Abstract,Final
Posted by Mantled with No comments
Abstract -
Final - variable is a constant; its value cannot be changed after its initialization.
Access Modifiers – Public, Private, Protected & Default
Posted by Mantled with No comments
Public - This is the least restrictive,accessible to entire project;
Default - If no access modifier is specified in the declaration, accessible only within package,not accessible in other packages or sub packages;
Protected - Accessible to all classes in the package and to all sub-classes of its class in any package where this class is visible.
Private -This is the most restrictive accessibility modifiers. These members are accessible only with in the same class.
JEE : Login Form HTML - JS - MySQL
Posted by Mantled with No comments
--Login---
C:\Program Files (x86)\MySQL\MySQL Server 5.6>mysql -u root -p
Enter password: **** //root
mysql> CREATE DATABASE db;
Query OK, 1 row affected (0.00 sec)
mysql> USE db;
Database changed
mysql> CREATE TABLE user_table(username varchar(25),password varchar(25),secureno int);
//check table ----------
--Login---
C:\Program Files (x86)\MySQL\MySQL Server 5.6>mysql -u root -p
Enter password: **** //root
//pointing db
mysql> USE db;
desc user_table;
///---Result-------
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(25) | YES | | NULL | |
| password | varchar(25) | YES | | NULL | |
| secureno | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
//to know prot no
mysql> show variables; //3306
//---------Imp--------- not used this resource to new forum site ,collected from
http://bigknol.com/open-blog/2013/07/eclipse-jee-development-tutorial/
,add mysql env variable screen shot also--------------------imp-------//
- Prerequisite for JSP/MySQL Application with Eclipse JEE Kepler.
- Download and Install MySQL Server 5.5 on your Windows Machine
- Install Tomcat Server6.0( 32-bit windows zip)
- Download MySQL Connector/j for connecting JSP to MySQL Server.(mysql-connector-java-5.1.25.zip, Platform Independent (Architecture Independent))
- Download Eclipse IDE for Java EE Developers 32 bit windows And unzip it
JSP MySQL Eclipse JEE Development Kepler Tutorial
Creating a database and Table using MySQL : Open cmd prompt (Windows+R and Type ‘cmd’) or use MySQL 5.5 Command line client. Change directory to MySQL Server 5.5 installed Path. (In this example path looks like : C:\mysql\MySQL Server 5.5\bin>)Create a new user in MYSQL Sever12mysql –u <user-name> -penter password: *****You can use root if you have super user privilege, or create a new user in MySQL, to create a new user:123CREATE USER ‘nikisurf’@’localhost’ IDENTIFIED BY ‘password’;GRANT ALL PRIVILEGES ON *.* TO ‘nikisurf’@’localhost’;Login as a new usermysql –u nikisurf -pCreate a new Database db and Selecting Database12CREATE DATABASE db;USE db;Create a new Table in MySQL called ‘info’1234CREATE TABLE info(username varchar(25),password varchar(25),firstname varchar(25),lastname varchar(25),address varchar(25),pincode int,phonenumber int);Open EclipseClick eclipse.exe file from unzipped folder and set a workspace(location of projects)Create a new Dynamic Web ProjectFile => New => Dynamic Web Project, and give Project name as ‘Info’ click Nextagain Next Finish.Connect MySQL to JSP with Eclipse KeplerAdd Library : MySQL Connector/jUnzip mysql-connector-java-5.1 and select mysql-connector-java-5.1.23-bin.jar file and drag and drop into the Project explorer of the Eclipse(info => WebContent => WEB-INF => lib).Start CodingRight Click on Info from Project Explorer => New => HTML File (Give Name as index.html)index.html123456789101112131415161718192021<!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Insert title here</title></head><body><h1>Add Info</h1><form action="add.jsp" method="post">User name : <input type="text" name="username" /><br />password : <input type="password" name="password" /><br />First name :<input type="text" name="firstname" /><br />Last name :<input type="text" name="lastname" /><br />address :<textarea cols="10" rows="15" name="address"></textarea><br />Pin code <input type="text" name="pincode" /><br /> <br />phone number <input type="text" name="phonenumber" /><br /><input type="submit" value="Add Details" /><br /></form></body></html>Create a new JSP file : Right Click on Info from Project Explorer => New => JSP File (Give Name as add.jsp) Insert the codes between body tag of the documentadd.jsp12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758<%@page import="java.sql.*" %><%@page import="java.io.*" %><%@page import="javax.sql.*" %><%@page import="java.sql.Connection" %><%String username=request.getParameter("username");String password=request.getParameter("password");String firstname=request.getParameter("firstname");String lastname=request.getParameter("lastname");String address=request.getParameter("address");String pincode=request.getParameter("pincode");String phonenumber=request.getParameter("phonenumber");Class.forName("com.mysql.jdbc.Driver");Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db","nikisurf","nikisurf");Statement st=con.createStatement();String sql="insert into info(username,password,firstname,lastname,address,pincode,phonenumber)values('"+username+"','"+password+"','"+firstname+"','"+lastname+"','"+address+"','"+pincode+"','"+phonenumber+"')";int flag=st.executeUpdate(sql);if(flag==1){out.println("Added!");}else{out.println("Failed");}response.sendRedirect("show.html");%>Create delete.html12345678910111213<!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Insert title here</title></head><body><form action="delete.jsp" method="post" >Enter First name to delete:<input type="text" name="username" /><input type="submit" value="delete" /></form></body></html>delete.jsp1234567891011121314151617181920212223242526272829<%@page import="java.sql.*" %><%@page import="java.io.*" %><%@page import="javax.sql.*" %><%@page import="java.sql.Connection" %><%String username=request.getParameter("username");Class.forName("com.mysql.jdbc.Driver");Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db","nikisurf","nikisurf");Statement st=con.createStatement();try{st.executeUpdate("DELETE FROM info WHERE username = '"+username+"'");boolean flag=true;if(flag==true){out.println("Deleted");}else{out.println("Not possible : error!");}}catch(Exception e){out.println("Exception");}%>show.html1234<form action="show.jsp" method="post">Enter User name<input type="text" name="username" /><input type="submit" value="show details" />show.jsp123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475<%@page import="java.sql.*" %><%@page import="javax.sql.*" %><%@page import="java.sql.Connection" %><%String username=request.getParameter("username");Class.forName("com.mysql.jdbc.Driver");Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db","nikisurf","nikisurf");Statement st=con.createStatement();String query="select * from info where username='"+username+"'";ResultSet rs=st.executeQuery(query);%><%while(rs.next()){%><table border="2" bordercolor="#2494b7"><tr><th>UserName</th><th>Password</th><th>First Name</th><th>Last Name</th><th>Address</th><th>Pin code</th><th>Mobile Phone</th></tr><tr><td><%=rs.getString(1)%></td><td><%=rs.getString(2)%></td><td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><%=rs.getString(5)%></td><td><%=rs.getString(6)%></td><td><%=rs.getString(7)%></td></tr></table><%}%>Run JEE Eclipse Info ProjectTo run tomcat server with Eclipse : Right Click on Info from Project Explorer =>Run as => Run on Server
Subscribe to:
Posts (Atom)


