3:44 pm - Wednesday December 11, 0047

Statement NOT NULL 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>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 Null {

	/**
	 * @param args
	 */

	// TODO Auto-generated method stub

	public static void main(String[] args) throws Exception {

		Class.forName("com.mysql.jdbc.Driver").newInstance();
		Connection conn = DriverManager.getConnection(
				"jdbc:mysql://localhost:3306/Arun", "root", "root");
		Statement st = conn.createStatement();

		st = conn.createStatement();
		ResultSet rs = st
				.executeQuery("SELECT name,id FROM EMP      WHERE salary IS NOT NULL");

		while (rs.next()) {
			String name = rs.getString(1);
			System.out.println(name);

		}

		rs.close();
		st.close();
		conn.close();

	}

}

Output:

This program returns the value of the name and where salary in the employee table is notnull.

Filed in: Z-A All Java Codes

Comments are closed.