understand the Mysql and Jdbc database connectivity code

understand the Mysql and Jdbc database connectivity code

understand the Mysql and Jdbc database connectivity code through example.

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 - 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
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
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  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 jdbc connectivity
mysql jdbc connectivity  i want to connect retrieve data from mysql using jdbc
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
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
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
JDBC, Java Database Connectivity
tutorials. Java Database Connectivity or JDBC for short is Java bases API... to the database developers uses JDBC API to perform insert, update, select... drivers for major databases. You can download the JDBC driver for your database
JDBC - Java Database Connectivity Tutorial
that explain you to understand JDBC Mysql Connection. The code include a class...JDBC - Java Database Connectivity Tutorials   ... 4.0 Java database connectivity (JDBC) is the Java Soft specification
JDBC Connectivity Code In Java
JDBC Connectivity Code In Java      ... in understanding JDBC Connectivity Code in Java. In this program, the code...;String 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 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
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 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
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
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
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-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  describe java program steps in order to get connectivity to database along with example
database connectivity
database connectivity  how to create database connectivity between HTML and sql server2005
JDBC Video tutorial - How to read Data from MySQL Database?
JDBC Beginners tutorial for reading the data from MySQL database... program, which connects to the MySQL database using pure type 4 JDBC driver.ADS...: Step 1: Connect to the MySQL database Following code connects to the MySQL
JDBC CONNECTIVITY
"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/abhi... connectivity Other JDBC Tutorials...JDBC CONNECTIVITY  import java.sql.Connection; import
JDBC access database
JDBC access database       JDBC is a Java Database Connectivity. The JDBC Connectivity provides API classes... that helps in understanding JDBC access database. The code illustrates the list
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
JDBC Components
Database Connectivity. For connectivity with the database we uses JDBC.... JDBC gives you the opportunity to communicate with standard database. JDBC... and retrieve results and updation to the database. The JDBC API is part of the Java
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
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
. 3) code and procedure to establish jdbc connectivity and to store...code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..  Dear sir
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
. 3) code and procedure to establish jdbc connectivity and to store...code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..  Dear sir
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
. 3) code and procedure to establish jdbc connectivity and to store...code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..  Dear sir
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
. 3) code and procedure to establish jdbc connectivity and to store...code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..  Dear sir
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
. 3) code and procedure to establish jdbc connectivity and to store...code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..  Dear sir
Java connectivity with MySQL
Java connectivity with MySQL  Java connectivity with MySQL
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
MySQL JDBC Driver pom dependency code
MySQL JDBC Driver pom dependency code  Hi, What is the POM dependency code for MySQL's latest JDBC Driver? I can download the MySQL driver from mysql website but I need to use it in a application which is based on Maven 3
Working with Database through JDBC
to work with database. For this you can write JDBC code in the action method of the managed bean. Let's understand through an example. The code of jdbc.jspADS...Working with Database through JDBC   
JDBC Video tutorial - How to delete Data in a MySQL Database?
Following code connects to the MySQL database and returns the JDBC Connection...JDBC Beginners tutorial for deleting the data into MySQL database... Database Connectivity API (JDBC) provides rich set of classes, interfaces
database connectivity problem
database connectivity problem  what if client dont have database with them then what is other way to run successfully our programm   Please visit the following link: http://www.roseindia.net/jdbc
JDBC Video tutorial - How to update Data in a MySQL Database?
Following code connects to the MySQL database and returns the JDBC Connection object...JDBC Beginners tutorial for updating the data into MySQL database The Java Database Connectivity API (JDBC) provides rich set of classes, interfaces
j2me mysql connectivity
j2me mysql connectivity  I do a project on reservation using j2me. I need a connectivity to a MYSQL database. How do I do this Thanks and regards Karthiga
Database Connectivity
Database Connectivity  I tried to establish database connection with sqlserver2008 through GlassFish server. When I set the path of sqljdbc.jar(E:\Glass Fish\glassfish-v2ur1\javadb\lib\sqljdbc.jar) it shows me error
database connectivity
database connectivity  i have written class.forName and getconnection in one method which returns connection string object under particular class and in someother class i want to call that for statement object
HTML code to servlet to database using jdbc
HTML code to servlet to database using jdbc  pls send me the code related to the title   Hi Friend, Try the following code:ADS...=DriverManager.getConnection("jdbc:odbc:student","",""); Statement stmt
Oracle Database connectivity probem
Oracle Database connectivity probem  hi Below is the code of oracle database connectivity, when i compile it, it will show the error... also set the environment variable like that .;E:\oracle\ora81\jdbc\lib
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
JDBC Connectivity - JDBC
JDBC Connectivity  my question is how to connect a Java program with MS-Access database?  Hello Use this code import java.sql.... String filename = "d:/java/mdbTEST.mdb"; String database = "jdbc

Ads