11:06 pm - Saturday May 27, 2017

Statement VIEWS Example program in java Jdbc mysql database

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Create Table and  Insert values:


Mysql>CREATE TABLE Employee(id int NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),name evarchar(10), salary int(10));

insert into Employee(name,salary) values("Arun",20000);

insert into Employee(name,salary) values("Prabhu",10000);

Java code:

package myjava1;

import java.sql.*;

public class Increment {

	public static void main(String[] args) {

		Connection con = null;
		String url = "jdbc:mysql://localhost:3306/";
		String dbName = "Arun";
		String driverName = "com.mysql.jdbc.Driver";
		String userName = "root";
		String password = "root";
		try {
			Class.forName(driverName).newInstance();
			con = DriverManager.getConnection(url + dbName, userName, password);
			try {
				Statement st = con.createStatement();
				String code = " Create VIEW sal As select * from Employee";

				st.executeUpdate(code);

				System.out.println(" process successfully created!");
			} catch (SQLException s) {
				System.out.println("Table already exists!");
			}
			con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Output:

Filed in: Z-A Hibernate codes

Comments are closed.