Convert String to Month Number in MySQL

George John
Updated on 30-Jul-2019 22:30:26

290 Views

Use the str_to_date() method −select month(str_to_date(yourColumnName, '%b')) from yourTableName;Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    MonthName varchar(100)    ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(MonthName) values('Jan'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(MonthName) values('Mar'); Query OK, 1 row affected (0.13 sec) Display all records from the table using select statement: mysql> select *from DemoTable;Output+----+-----------+ | Id | MonthName | +----+-----------+ | 1 | Jan ... Read More

Create Table with Decimal Values using JDBC

Anvi Jain
Updated on 30-Jul-2019 22:30:26

767 Views

An unpacked floating-point number that cannot be unsigned. In the unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.To define a column with a decimal value as datatype follow the syntax given below −column_name DECIMAL(P, D);Where −P is the precision representing the number of digits (range 1 to 65)D is the scale representing the number of digits after the decimal point.Note − in MySQL D should be describe customers; +------------+---------------+------+-----+---------+-------+ | Field      | Type          | ... Read More

Return the First N Letters of a Column in MySQL

Rama Giri
Updated on 30-Jul-2019 22:30:26

159 Views

To return the first n letters, use the LEFT() function. Following is the syntax −select left(yourColumnName, yourValue) from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CourseTitle text    -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(CourseTitle) values('Java with Spring and Hibernate framework'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable(CourseTitle) values('Python Web Development'); Query OK, 1 row affected (0.22 sec)Display all records from the table using ... Read More

C++ Program for Comb Sort

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

357 Views

The basic idea of comb sort and the bubble sort is same. In other words, comb sort is an improvement on the bubble sort. In the bubble sorting technique, the items are compared with the next item in each phase. But for the comb sort, the items are sorted in a specific gap. After completing each phase, the gap is decreased. The decreasing factor or the shrink factor for this sort is 1.3. It means that after completing each phase the gap is divided by 1.3. Time Complexity is O(n log n) for best case. O(n2/2nP) (p is number of ... Read More

Inheritance and Friendship in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

2K+ Views

In C++, the friendship is not inherited. It means that, if one parent class has some friend functions, then the child class will not get them as friend.In this example it will generate an error because the display() function is friend of MyBaseClass but not the friend of MyDerivedClass. The display() can access the private member of MyBaseClass.Example#include using namespace std; class MyBaseClass {    protected:       int x;    public:       MyBaseClass() {          x = 20;       }       friend void display(); }; class MyDerivedClass : public MyBaseClass {    private:       int y;    public:       MyDerivedClass() {          x = 40;       } }; void display() {    MyDerivedClass derived;    cout

Delete All Records from a Table in Oracle Using JDBC API

Rishi Raj
Updated on 30-Jul-2019 22:30:26

2K+ Views

The SQL TRUNCATE statement is used to delete all the records from a table.SyntaxTRUNCATE TABLE table_name;To delete all the records from a table from using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.Following JDBC program ... Read More

MongoDB Pull with Positional Operator

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

177 Views

Use $pull operator along with positional operator($) in MongoDB. Let us first create a collection with documents −> db.pullWithPositionalOperatorDemo.insertOne( ...   { ...      _id: 100, ...      "StudentDetails": [ ...         { ...            "StudentId": "STU-1", ...            "StudentFavouriteSubject": ["MongoDB", "Java"] ...         }, ...         { ...            "StudentId": "STU-2", ...            "StudentFavouriteSubject": ["PHP", "MySQL"] ...         } ...      ] ...   } ... ); { ... Read More

Set Label Content to Right Justified and Top Aligned in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

137 Views

To set the text of the label component to be right-justified and top-aligned, you need to set the alignment. Set the label to be on the right and top aligned −JLabel label = new JLabel("Fav Sports", JLabel.RIGHT); label.setVerticalAlignment(JLabel.TOP);Here, we have set the size of the label as well as the color that includes foreground and background color −label.setPreferredSize(new Dimension(220, 70)); label.setOpaque(true); label.setBackground(Color.YELLOW); label.setForeground(Color.RED);The following is an example to set the content of the lable to be right-justified and top-aligned −package my; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo ... Read More

Update All Rows by Prefixing a Line in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

325 Views

For this, use the CONCAT() function. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject varchar(200)    ); Query OK, 0 rows affected (1.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject) values('MySQL'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Subject) values('Java'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+---------+ | Id | Subject | +----+---------+ ... Read More

Store Decimal Values in a Table Using PreparedStatement in JDBC

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

1K+ Views

To insert records into a table that contains a decimal value using PreparedStatement you need to −Register the driver − Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement − Create a PreparedStatement object using the prepareStatement() method of the Connection interface. Pass the INSERT query with place holders to this method in String format as a parameter.PreparedStatement pstmt = con.prepareStatement("INSERT ... Read More

Advertisements