Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet understand the Mysql and Jdbc database connectivity code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sasi kumar
understand the Mysql and Jdbc database connectivity code
2 Answer(s)      6 years and 8 months ago
Posted in : JSP-Servlet


understand the Mysql and Jdbc database connectivity code through example.


Advertisement
View Answers

April 9, 2008 at 8:14 PM


See the Given JSP Example Code
-------------------------------

Servletform.html

<html>
<title>registration form</title>

<head>

<script language="JavaScript">

function isProper(string) {

if (!string) return false;
var iChars = "*|,\":<>[]{}`\';()@&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
return true;
}
function validateForm(theForm){

if(theForm.firstname.value==""){
//Please enter accountholder
alert("Enter the First Name.");
theForm.firstname.focus();
return false;
}

if (isProper(theForm.firstname.value) == false) {
alert("Please enter a valid First Name.");
theForm.firstname.focus();
return false;
}

if(theForm.firstname.value.length > 20) {
alert("Maximum 20 characters allowed for 'First Name'.")
theForm.firstname.focus() ;
return false;
}

if(theForm.address.value==""){
//Please enter accountholder
alert("Enter the address.");
theForm.address.focus();
return false;
}

if(theForm.email.value==""){
//Please enter accountholder
alert("Enter the E-mail address.");
theForm.email.focus();
return false;
}

if(theForm.contect.value==""){
//Please enter accountholder
alert("Enter the contect number.");
theForm.contect.focus();
return false;
}
return true;
}

</script>
</head>
<body>
<table border="1" width="50%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<h2>Registration form</h2>
<form method="GET" action="DataInsertServletExam" onsubmit="return validateForm(this);">
<table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><b>Name:</b></td>
<td><input type="text" name="firstname" size="30"></td>
</tr>
<tr><td><b>Address:</b></td>
<td><input type="text" name="address" size="50"></td>
</tr>
<tr>
<td><b>E-mail:<b></td>
<td><input type="text" name="email" size="30"></td>
</tr>
<tr><td><b>Contect No:</b></td>
<td><input type="text" name="contect" size="30"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset">
</td>

</tr>
</table>
</form>
<p>&nbsp;</p>
</tr>
</td>
</table>
</body>

</html>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
version="2.4">
<servlet>
<servlet-name>InsertDataExample</servlet-name>
<servlet-class>DataInsertServletExam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InsertDataExample</servlet-name>
<url-pattern>/DataInsertServletExam</url-pattern>
</servlet-mapping>

</web-app>


DataInsertServletExam.java

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DataInsertServletExam extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String firstname=request.getParameter("firstname");
String address=request.getParameter("address");
String email=request.getParameter("email");
String contect=request.getParameter("contect");
int val = st.executeUpdate("insert regiform values('"+firstname+"','"+address+"','"+email+"','"+contect+"')");
con.close();
out.println("Successfully insert data in database");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

}
}


April 9, 2008 at 8:29 PM


According to above-mentioned code, you need to create three different files namely
1. Servletform.html
2. web.xml and
3. DataInsertServletExam.java

Once you done with these three files just run your application to see the output.

This Example is a good mix of various Java Technologies such as Servlet, JavaScript and java. You not only learn how to use these java technologies collectively but also you will understand the Mysql and Jdbc database connectivity code through example.


Related Tutorials/Questions & Answers:
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
Advertisements
jdbc connectivity to mysql tutorial
jdbc connectivity to mysql tutorial  here is complete jdbc connectivity to mysql tutorial for newbies. Person who don't even know how to install mysql and don't know about which driver to use can do with ease
database connectivity using mysql
database connectivity using mysql  java file: eg1.java package eg...[]) throws SQLException { try { String connectionURL = "jdbc:mysql... seconds) I am using Netbeans 5.5, mysql server 5.0, to get data from table
database connectivity - JDBC
database connectivity  example java code for connecting Mysql database using java  Hi friend, Code for connecting Mysql database using...."); Connection conn = null; String url = "jdbc:mysql://localhost:3306
mysql jdbc connectivity
mysql jdbc connectivity  i want to connect retrieve data from mysql using jdbc
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
database connectivity - JDBC
database connectivity  can u ppl pls provide me with database connectivity programs with MSacces   Hi Friend, If you havn't create your... a user DSN 4. Select Microsoft Access Driver(*.mdb) 5. Select database name
MySQL connectivity - JDBC
MySQL connectivity  hi all, i am not able to connect Mysql to java ..as i connect it ..i am getting the error ..saying classNotFoundException... to "com.mysql.jdbc.Driver" class not found In the lib folder "mysql-connector-java-5.0.6-bin.jar
database connectivity in java - JDBC
database connectivity in java  import java.io.*; import java.awt.... images\\collapsed.gif"); l1=new JLabel("Code:"); l2=new JLabel("Name:"); l3=new JLabel("Mobile:"); l4=new JLabel("Email:"); l5=new JLabel("Code
JDBC - Java Database Connectivity Tutorial
JDBC - Java Database Connectivity Tutorials  ...; New Features in JDBC 4.0 Java database connectivity (JDBC) is the Java... rows. JDBC Tutorials JDBC (Java Database Connectivity
JDBC, Java Database Connectivity
tutorials. Java Database Connectivity or JDBC for short is Java bases API... driver as per your application needs. About JDBC Java Database Connectivity... to the database developers uses JDBC API to perform insert, update, select
database connectivity using jsp code
database connectivity using jsp code  i have two tables employee...),'bbbb','bbbb'); so this syntax is possible to use in jsp code based... key)this is employee table schema in mysql adduser->(Emp_ID varchar(50),Ename
DataBase connectivity in java with Microsoft sql server2000 - JDBC
DataBase connectivity in java with Microsoft sql server2000  How i can achieve database connectivity with Microsoft sql server2000 in my java source code
JDBC Connectivity Code In Java
JDBC Connectivity Code In Java      ... in understanding JDBC Connectivity Code in Java. In this program, the code...;url = "jdbc:mysql://localhost:3306/";   
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
Database connectivity with jsp code - JSP-Servlet
Database connectivity with jsp code  I have written a program in java having connectivity with online_exam. Its working properly. Connection has been established and the code in java is showing the output. But the problem
JDBC CONNECTIVITY
file in environment variable.   Java Mysql connectivity Other JDBC...JDBC CONNECTIVITY  How do i connect my database to java. I have the connector file and i place it in lib of jdk folder and installed the jdbc driver
The required JDBC drivers to establish connectivity to my database part of the JDK.
The required JDBC drivers to establish connectivity to my database part of the JDK.  Are all the required JDBC drivers to establish connectivity to my database part of the JDK
connectivity with mysql
connectivity with mysql  if this code of roseindia doesnt work.../phpdatabase/Check-PHP-MySQL-Connectivity.html   Please visit the following.../tutorial/php/phpdatabase/ http://www.roseindia.net/sql/mysql-example/php-mysql
Jdbc Mysql Connection Url
JDBC Mysql Connection Url       The Tutorial want to illustrate a code that explain you to understand JDBC Mysql Connection. In this program, the code explain the JDBC url and string
JDBC CONNECTIVITY
"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/abhi... connectivity Other JDBC Tutorials...JDBC CONNECTIVITY  import java.sql.Connection; import
JDBC-Odbc Connectivity
JDBC-ODBC Connectivity       The code illustrates an example from JDBC-ODBC Connectivity. The code helps you in retrieve the name and size of the column
database connectivity
database connectivity  how to create database connectivity between HTML and sql server2005
database connectivity
database connectivity  describe java program steps in order to get connectivity to database along with example
connectivity - JDBC
connectivity  I hav MySQL 5.0, JDK 1.5, Tomcat 5.0 in my system when I tried to connect to database and insert data it is showing exeception..., Please check the mysql-connector-java-5.0.6-bin.jar file for Connection
Connectivity with sql in detail - JDBC
; String url = "jdbc:mysql://localhost:3306/"; String dbName... the following link: http://www.roseindia.net/jdbc/jdbc-mysql...Connectivity with sql in detail  Sir/Madam, I am
Java connectivity with MySQL
Java connectivity with MySQL  Java connectivity with MySQL
database connectivity
with database but i m not able to Code is ot giving any error and there is no update in database plsss somebody can help code is here package newpackage; import...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql
connectivity - JDBC
connectivity  How can we connect sql server using Java   Hi Friend, By using JDBC drivers, you can connect SQL server with java. Please visit the following link: http://www.roseindia.net/jdbc/jdbc.shtml
 

 

 

DMCA.com