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

 
 


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

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 Pages:
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
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
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
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 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
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
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 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
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/";   
JDBC CONNECTIVITY
"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/abhi... connectivity Other JDBC Tutorials...JDBC CONNECTIVITY  import java.sql.Connection; import
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-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
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
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
Java database connectivity
Java database connectivity  Hi sir I need a code to create an application where user enter name in text box and that should be stored in database... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root
regarding connectivity program only - JDBC
regarding connectivity program only  can u give me code regarding..., i am sending simple code of connectivity import java.sql.*; public... = "jdbc:mysql://192.168.10.211:3306/"; String db = "amar"; String driver
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
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
JDBC CONNECTIVITY - JDBC
JDBC CONNECTIVITY  String jclass="sun.jdbc.odbc.JdbcOdbcDriver"; Class.forName(jclass); String dsn= "Jdbc:Odbc:Employee"; Connection con... = con.prepareStatement("insert into detail values(?,?,?,?)"); I am a bigner in Jdbc so please tell
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
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 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
Eclipse Connectivity - JDBC
Eclipse Connectivity  Hello Friends.. I want to do connectivity with eclipse 3.4 Genemade with mysql Database. can u please help me to how to do connectivity..and which plugins are required for it. i have try to do
mysql jdbc connectivity
mysql jdbc connectivity  i want to connect retrieve data from mysql using jdbc
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
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
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
jdbc connectivity through jsp
jdbc connectivity through jsp  my code: <%@ page language="java... = ""; String url = "jdbc:mysql://localhost/interviewer... at line 20 17: String url = "jdbc:mysql://localhost/interviewer"; 18
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
Jdbc connectivity by type 4 driver
Jdbc connectivity by type 4 driver  I have done a code with database connectivity with driver 4,it copiles,but while running it is showing java.lang.ClassNotFound exception..the code is following... import java.sql.*; class
JDBC batch
Database Connectivity. This Connectivity provides you an API, that provides you.... The backend can be SQL-2000,2005,MySql. A batch in JDBC is a set of sql statement  altogether to the database for execution. Understand with Example We have already
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code... the following link: JDBC MySQl Connectivity   I have mysql-connector... = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver
Java vs Oracle Connectivity - JDBC
connection with oracle database?  Hi Friend, Use Oracle with Java...) Load and Register the JDBC driver:*********** DriverManager.registerDriver...("oracle.jdbc.driver.OracleDriver"); 3) Connect to database:*********** a) If you
connectivity step
connectivity step  sir.pls give me step one by one for connect...*; import oracle.sql.*; 2) Load and Register the JDBC driver... Class.forName("oracle.jdbc.driver.OracleDriver"); 3) Connect to database:*** a) If you
in connectivity - Hibernate
insertted  Hi friend, This is connectivity and hibernate configuration code com.mysql.jdbc.Driver jdbc:mysql://localhost
Check PHP MySQL Connectivity
Check PHP MySQL Connectivity: The first step of any kind of connectivity... can connect a PHP page with MySQL server. Following piece of code will help... or not. Code 1: <?php $con=mysql_connect("localhost","
Help me on database connectivity in J2ME - Java Beginners
Help me on database connectivity in J2ME  i want help in J2ME. i want code for database connection with MySQL. spcl to fecth and insert data from databse. please help me
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
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.jsp...Working with Database through JDBC   
jdbc mysql - JDBC
=DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","root... be problem in your mySql, the above code is working fine. first you check... you code for displaying all table name from database. package javacode
JDBC - JDBC
ILLUSTRATIONS to understand the way to do work in JDBC with syntaxes  Hi... Connect Example."); Connection conn = null; String url = "jdbc:mysql...JDBC  i am goint to work on JDBC and i knew oracle but very poor
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything working fine in localhost , but facing a simple problem in connectivity with database from my web site. In my local host-- when I am typing following code
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything working fine in localhost , but facing a simple problem in connectivity with database from my web site. In my local host-- when I am typing following code
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything working fine in localhost , but facing a simple problem in connectivity... following code in online connectivity ---- Class.forName
JDBC Exception
the execution of program. Exception Occurred in JDBC Connectivity when a connection... = "jdbc:mysql://localhost:3306/"; db = "komal"... JDBC Exception      
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 (Java Database Connectivity) -Tutorials
JDBC (Java Database Connectivity) -Tutorials  ... package that can be used with any database providing JDBC connectivity... driver. JDBC-ODBC Bridge - Open Database Connectivity (ODBC

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.