Install perl DBI using Perl Package Manager(PPM) using internet.
This is the simple program.
#!c:/Perl/bin/perl.exe
# PERL MODULES WE WILL BE USING
use DBI;
print "Content-type:text/html\n\n";
$dbh = DBI->connect('dbi:mysql:jsp','root','paasowrd')or die "Connection Error: $DBI::errstr\n";
$sql = "select * from users";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
while (@row = $sth->fetchrow_array) {
print "@row\n";
}
Wednesday, February 3, 2010
Perl on local Wamp Server
Install perl and made these some modification in httpd.conf file of apache web server.
In Directory add these two bold word.
Options Indexes FollowSymLinks Includes ExecCGI
Add these two bold word.
DirectoryIndex index.php index.php3 index.html index.htm index.cgi index.pl
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
Now create a folder in c:/wamp/www/ and creating a test.pl file
#!c:/Perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
Open in the browser http://localhost/your_folder/test.pl you see the environment variable of the system.
In Directory add these two bold word.
Options Indexes FollowSymLinks Includes ExecCGI
Add these two bold word.
DirectoryIndex index.php index.php3 index.html index.htm index.cgi index.pl
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
Now create a folder in c:/wamp/www/ and creating a test.pl file
#!c:/Perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
Open in the browser http://localhost/your_folder/test.pl you see the environment variable of the system.
JSP connectivity with MS-SQL SERVER
Download Microsoft SQL Server JDBC Driver 2.0 for java on following url:
http://www.microsoft.com/downloads/details.aspx?FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9&displaylang=en
or
http://go.microsoft.com/fwlink/?LinkId=144633&clcid=0x409
It will gives sqljdbc_2.0.1803.100_enu.exe. Run it, will gives a zip, extract them. Copy sqljdbc4.jar in Apache Tomcat 6.0.14\lib and don't forget to restart the Tomcat-Apache webserver.
Write down the following code, as i think it is understandable.
<%@ page language="java" import="java.sql.*" %>
<%
Connection conn = null;
Statement st =null;
ResultSet rst = null;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String strUrl = "jdbc:sqlserver://localhost:1433;username=jivasingh;password=jivasingh12345;databasename=imt";
conn = DriverManager.getConnection(strUrl);
st = conn.createStatement();
out.println("connected");
String queryCountry = "Select * from users";
ResultSet countResultSet = st.executeQuery(queryCountry);
while(countResultSet.next()){
out.println(countResultSet.getString("name"));
out.println("
");
}
}catch(Exception e){
out.println(e);
}
%>
Hahaha....happy .....Gracias....you have just connect with SQL server...
http://www.microsoft.com/downloads/details.aspx?FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9&displaylang=en
or
http://go.microsoft.com/fwlink/?LinkId=144633&clcid=0x409
It will gives sqljdbc_2.0.1803.100_enu.exe. Run it, will gives a zip, extract them. Copy sqljdbc4.jar in Apache Tomcat 6.0.14\lib and don't forget to restart the Tomcat-Apache webserver.
Write down the following code, as i think it is understandable.
<%@ page language="java" import="java.sql.*" %>
<%
Connection conn = null;
Statement st =null;
ResultSet rst = null;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String strUrl = "jdbc:sqlserver://localhost:1433;username=jivasingh;password=jivasingh12345;databasename=imt";
conn = DriverManager.getConnection(strUrl);
st = conn.createStatement();
out.println("connected");
String queryCountry = "Select * from users";
ResultSet countResultSet = st.executeQuery(queryCountry);
while(countResultSet.next()){
out.println(countResultSet.getString("name"));
out.println("
");
}
}catch(Exception e){
out.println(e);
}
%>
Hahaha....happy .....Gracias....you have just connect with SQL server...
Sunday, January 24, 2010
Mysql Connectivity with JSP
Download connector / j Jar file and copy in to Apache Software Foundation\Apache Tomcat 6.0.14\lib folder and restart tomcat server.
Now creat a connection.jsp file to test the connectivity..
<%@ page language="java" import="java.sql.*" %>
<%
Connection conn = null;
Statement st =null;
ResultSet rst = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql:///databsename","mysql-username", "mysql-password");
if(!conn.isClosed())
out.println("Successfully connected to " +"MySQL server using TCP/IP...\n");
} catch (SQLException ex) {
// handle any errors
out.println("SQLException: " + ex.getMessage());
out.println("SQLState: " + ex.getSQLState());
out.println("VendorError: " + ex.getErrorCode());
}
%>
Now creat a connection.jsp file to test the connectivity..
<%@ page language="java" import="java.sql.*" %>
<%
Connection conn = null;
Statement st =null;
ResultSet rst = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql:///databsename","mysql-username", "mysql-password");
if(!conn.isClosed())
out.println("Successfully connected to " +"MySQL server using TCP/IP...\n");
} catch (SQLException ex) {
// handle any errors
out.println("SQLException: " + ex.getMessage());
out.println("SQLState: " + ex.getSQLState());
out.println("VendorError: " + ex.getErrorCode());
}
%>
Saturday, July 14, 2007
Welcome to new world
Hi,
To all,
I am imteyaz from delhi... This is my first weblog............ I am waiting for others valuable comments.......and recommendations........
To all,
I am imteyaz from delhi... This is my first weblog............ I am waiting for others valuable comments.......and recommendations........
Subscribe to:
Posts (Atom)