1. Installation of Netbeans software. Clink on following link and download Java EE
https://netbeans.org/downloads/
https://netbeans.org/downloads/
2. Download sqlitejdbc-v056.jar file from following link
3. Open Netbeans Software and click on Java web application.
4. In NetBeans add libraries by going to Tools –> Libraries and Click ADD LIBRARY. An Add Library dialog will appear
5. Add the driver JAR file location into CLASSPATH tab
6. In the Projects window Right Click on Libraries folder and Select Add Library…
7. Click on Add Library and select Sqlite3.
8. Create select.JSP page for connectivity and fetching value from database. Source code for fetching value is given below.
// source code start
<%@ page import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Select Value from sqlite database</h1>
<%
String sDriverName = "org.sqlite.JDBC";
Class.forName(sDriverName);
String sJdbc = "jdbc:sqlite";
// database name pu.db and store locationis d drive mention below
String sTempDb = "d:\\pu.db";
String sDbUrl = sJdbc + ":" + sTempDb;
Connection connection = DriverManager.getConnection(
sDbUrl);
Statement statement = connection.createStatement() ;
ResultSet resultset = statement.executeQuery("select * from ajay") ;
%>
<TABLE BORDER="1">
<TR>
<TH>ID</TH>
<TH>Name</TH>
</TR>
<% while(resultset.next()){ %>
<TR>
<TD> <%= resultset.getString(1) %></td>
<TD> <%= resultset.getString(2) %></TD>
</TR>
<% } %>
</TABLE>
</body>
</html>
10. After running you can see output screen like
11. Click on submit button and you will be shown data fetching from database shown.
12. Congratulation for database connectivity. If you have any doubt send message.
// source code start
<%@ page import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Select Value from sqlite database</h1>
<%
String sDriverName = "org.sqlite.JDBC";
Class.forName(sDriverName);
String sJdbc = "jdbc:sqlite";
// database name pu.db and store locationis d drive mention below
String sTempDb = "d:\\pu.db";
String sDbUrl = sJdbc + ":" + sTempDb;
Connection connection = DriverManager.getConnection(
sDbUrl);
Statement statement = connection.createStatement() ;
ResultSet resultset = statement.executeQuery("select * from ajay") ;
%>
<TABLE BORDER="1">
<TR>
<TH>ID</TH>
<TH>Name</TH>
</TR>
<% while(resultset.next()){ %>
<TR>
<TD> <%= resultset.getString(1) %></td>
<TD> <%= resultset.getString(2) %></TD>
</TR>
<% } %>
</TABLE>
</body>
</html>
//source code end
8. For fetching database table values create .html page. This html linked with select.jsp page for fetching value.
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="select.jsp">
<input type="submit" name="btnsearch">
</form>
</body>
</html>
9. Select.html file select and click on run file option
10. After running you can see output screen like
11. Click on submit button and you will be shown data fetching from database shown.
12. Congratulation for database connectivity. If you have any doubt send message.
No comments:
Post a Comment