Create Table with Auto Increment Column in MySQL using JDBC

Anvi Jain
Updated on 29-Jun-2020 13:12:06

2K+ Views

While creating a table, in certain scenarios, we need values to column such as ID, to be generated/incremented automatically. Various databases support this feature in different ways.In MySQL database you can declare a column auto increment using the following syntax.CREATE TABLE table_name(    ID INT PRIMARY KEY AUTO_INCREMENT,    column_name1 data_type1,    column_name2 data_type2,    column_name3 data_type3,    column_name4 data_type4,    ............ ........... );MySQL query to create a table with auto-incremented column.CREATE TABLE Sales(    ID INT PRIMARY KEY AUTO_INCREMENT,    ProductName VARCHAR (20) NOT NULL,    CustomerName VARCHAR (20) NOT NULL,    DispatchDate date,    DeliveryTime timestamp,    Price ... Read More

NavigableMap floorKey Method in Java

Chandu yadav
Updated on 29-Jun-2020 13:11:27

156 Views

The floorKey() method is used to get floor key i.e. to return the greatest key less than or equal to the given key, or null if there is no such key.The following is an example to get floor key from NavigableMapExample Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       NavigableMap n = new TreeMap();       n.put("A", 498);       n.put("B", 389);       n.put("C", 868);       n.put("D", 988);       n.put("E", 686);       n.put("F", 888);       n.put("G", 999);       ... Read More

Check if IdentityHashMap is Empty in Java

George John
Updated on 29-Jun-2020 13:10:42

186 Views

Check whether a Map is empty or not using the isEmpty() method.Let us first create a IdentityHashMap and add some elements to itMap m= new IdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450);Now, use the following method to check whether the Map is empty or not. Since we added some elements above, therefore the Map is not emptyn.isEmpty();Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       Map m = new IdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); ... Read More

Fetch Value for a Specific Key in Java IdentityHashMap

Arjun Thakur
Updated on 29-Jun-2020 13:10:08

2K+ Views

To fetch the value for a specific key, use the get() method.As a parameter, set the key you want to fetch and fetch the value.Let’s say you need to fetch value of key 3get("3")The following is an example to fetch the value for a specific key in Java IdentityHashMap −Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       Map m = newIdentityHashMap();       m.put("1", 100);       m.put("2", 200);       m.put("3", 300);       m.put("4", 150);       m.put("5", 110);       m.put("6", 50); ... Read More

Main Method Accept Arguments Other Than String Array in Java

Maruthi Krishna
Updated on 29-Jun-2020 13:08:04

5K+ Views

The public static void main() method accepts an array of values of the type String Java from the user.public class{    public static void main(String[] args){    } }You can pass them at the time of execution right after the class name separated with spaces as −java ClassName 10 20 30And, in the program (from the main method) you can extract these values from the String array and use.ExampleFor example, you can use command line arguments to pass a and b in the above program as −public class Sample {    public static void main(String[] args){       int ... Read More

SMTP Protocol Client in Python using smtplib

George John
Updated on 29-Jun-2020 13:05:39

1K+ Views

Python's standard library has 'smtplib' module which defines an SMTP client session object that can be used to send mail via Python program.A mail server is an application that handles and delivers e-mail over the internet. Outgoing mail servers implement SMTP, or Simple MailTransfer Protocol, servers which are an Internet standard for email transmission.Incoming mail servers come in two main varieties. POP3, or Post office protocol and IMAP, or Internet Message Access Protocol.smptlib.SMTP()functionThis function returns an object of SMTP class. It encapsulates and manages a connection to an SMTP or ESMTP server. Following arguments are defined in the signature of ... Read More

Change Return Type of Main Method in Java

Maruthi Krishna
Updated on 29-Jun-2020 13:05:29

3K+ Views

The public static void main() method is the entry point of the Java program. Whenever you execute a program in Java, the JVM searches for the main method and starts executing from it.You can write the main method in your program with return type other than void, the program gets compiled without compilation errors. But, at the time of execution JVM does not consider this new method (with return type other than void) as the entry point of the program.It searches for the main method which is public, static, with return type void, and a String array as an argument.public static int ... Read More

Why Main Method Must Be Static in Java

Maruthi Krishna
Updated on 29-Jun-2020 13:02:18

2K+ Views

Static − If you declare a method, subclass, block, or a variable static it is loaded along with the class.In Java whenever we need to call an (instance) method we should instantiate the class (containing it) and call it. If we need to call a method without instantiation it should be static. Moreover, static methods are loaded into the memory along with the class.In the case of the main method, it is invoked by the JVM directly, so it is not possible to call it by instantiating its class. And, it should be loaded into the memory along with the ... Read More

Add a Not Null Column in MySQL

Arjun Thakur
Updated on 29-Jun-2020 13:01:56

4K+ Views

You can add a not null column at the time of table creation or you can use it for an existing table.Case 1 − Add a not null column at the time of creating a table. The syntax is as followsCREATE TABLE yourTableName (    yourColumnName1 dataType NOT NULL,    yourColumnName2 dataType    .      .    .    N );The query to create a table is as followsmysql> create table NotNullAtCreationOfTable    -> (    -> Id int not null,    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.60 sec)In the above table, we ... Read More

Declare Main Method as Private, Protected or Without Access Modifier in Java

Maruthi Krishna
Updated on 29-Jun-2020 13:00:49

7K+ Views

Java provides various access specifiers namely private, public and protected etc...The Private modifier restricts the access of members from outside the class. A class and interface cannot be public.The Public access modifier can be associated with class, method, constructor, interface, etc. public can be accessed from any other class.The protected access modifier can be associated with variables, methods, and constructors, which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.The default access modifier does not have keyword a variable or method declared ... Read More

Advertisements