how to create a connecction in mysql jsp?
How to create mysql connectiion using jsp?
Ans:-
Creating connection using mysql,jsp
<%@ page language="java" import="java.sql.*" %>
<%
Connection con = null;
String databaseDriver = "com.mysql.jdbc.Driver";
String connectionURL="";
try {
connectionURL = "jdbc:mysql://localhost:3306/DataBaseName";
Class.forName(databaseDriver).newInstance();
con = DriverManager.getConnection(connectionURL, "username", "password");
}catch(Exception e){
out.print("Please wait 'http://rajdeokumarsingh1.blogspot.in/' will be back soon ");
}
%>
ow wait before doing this you have to put mySqlConnector.jar in lib folder of jdkx.xx.Ok
Doooooooooooooooooooooooooooooone!!!!!!!!!!!!!!!
you can download mySqlConnector.jar from this site
http://dev.mysql.com/downloads/connector/j/3.1.html
Extract it and paste on lib folder that's it
Now you done it
Thanks
Ans:-
Creating connection using mysql,jsp
<%@ page language="java" import="java.sql.*" %>
<%
Connection con = null;
String databaseDriver = "com.mysql.jdbc.Driver";
String connectionURL="";
try {
connectionURL = "jdbc:mysql://localhost:3306/DataBaseName";
Class.forName(databaseDriver).newInstance();
con = DriverManager.getConnection(connectionURL, "username", "password");
}catch(Exception e){
out.print("Please wait 'http://rajdeokumarsingh1.blogspot.in/' will be back soon ");
}
%>
ow wait before doing this you have to put mySqlConnector.jar in lib folder of jdkx.xx.Ok
Doooooooooooooooooooooooooooooone!!!!!!!!!!!!!!!
you can download mySqlConnector.jar from this site
http://dev.mysql.com/downloads/connector/j/3.1.html
Extract it and paste on lib folder that's it
Now you done it
Thanks
How to Do Pagination using Jsp,Servlet ?
create a table in mysql.
Create table pagination
(
id int ,
title varchar (50),
Description varchar(50),
)
Step 2:create the Database Connection.
create a connection.jsp file
Simple code:-
String connectionURL = "jdbc:mysql://localhost:3306/DatabaseName";
Connection con = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL, "username", "Password");
save it to connection.jsp
Connection Created
Step 3:- Create a search.jsp file
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
Welcome to music | Movie Search Engine
<%@include file="music.html"%>
/*
String connectionURL = "jdbc:mysql://localhost:3306/";
Connection con = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL, "", "");
*/
<%@ include file="connection.jsp"%>
<%
Statement statement = null;
ResultSet rs = null;
try {
statement = con.createStatement();
String qs=request.getParameter("q");
if(qs==null)
qs="";
String item=request.getParameter("item");
if(item==null){item="0";}
int indexcounter=Integer.parseInt(item);
String query1 = "select count(*) from music_search where title LIKE '%"+qs+"%' order by id desc limit "+indexcounter+", 5";
Statement stat1 = con.createStatement();
ResultSet rs1 = stat1.executeQuery(query1);
rs1.next();
int resultcounter=0;
//resultcounter_blankresult=resultcounter;
resultcounter=rs1.getInt(1);
String QueryString = "SELECT * from music_search where title LIKE '%"+qs+"%' order by id desc limit "+indexcounter+", 5";
rs = statement.executeQuery(QueryString);
%>
<%
while (rs.next()) {
%>
<%}%>
<%
// close all the connections.
}catch (Exception ex){
%>
<%
out.println("Unable to connect to database.");
}
%>
No comments:
Post a Comment