Lowercase String with First Letter in Uppercase in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

179 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (1.32 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('JOhn'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('CHRIS'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('DAVID'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('RObert'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+--------+ | Name ... Read More

Sorting Algorithm That Improves on Selection Sort

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

305 Views

Here we will see some improvements on selection sort. As we know that the selection sort works by taking either the minimum or maximum element from the array and place that element at correct position. In this approach, we want to sort the array in both ways. Here we will take the max and min simultaneously, then sort the array from two end. Let us see the algorithm to get better idea.AlgorithmtwoWaySelectionSort(arr, n)begin    for i := 0, and j := n-1, increase i by 1, and decrease j by 1, until i>=j, do       min := minimum ... Read More

Understanding Sizeof in C: Why It's Never Executed

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

194 Views

The sizeof function (Sometimes called operator) is used to calculate the size of the given argument. If some other functions are given as argument, then that will not be executed in the sizeof.In the following example we will put one printf() statement inside the loop. Then we will see the output.Example#include double my_function() {    printf("This is a test function");    return 123456789; } main() {    int x;    x = sizeof(printf("Hello World"));    printf("The size: %d", x);    x = sizeof(my_function());    printf("The size: %d", x); }OutputThe size: 4 The size: 8The printf() is not executed which is ... Read More

Returning Multiple Values from Function Using Tuple and Pair in C++

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

3K+ Views

In C or C++, we cannot return more than one value from a function. To return multiple values, we have to provide output parameter with the function. Here we will see another approach to return multiple value from a function using tuple and pair STL in C++.The Tuple is an object capable to hold a collection of elements, where each element can be of different types.The pair can make a set of two values, which may be of different types. The pair is basically a special type of tuple, where only two values are allowed.Let us see one example, where ... Read More

Drop Table from Oracle Database Using JDBC API

Arushi
Updated on 30-Jul-2019 22:30:26

271 Views

You can insert records into a table using the INSERT query.SyntaxINSERT INTO TABLE_NAME (column1, column2, column3, ...columnN) VALUES (value1, value2, value3, ...valueN); Or, INSERT INTO TABLE_NAME VALUES (value1, value2, value3, ...valueN);To insert a record into a table in a database 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() ... Read More

Can MongoDB Return Result of Increment?

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

150 Views

Yes, you can achieve this with findAndModify(). Let us first create a collection with documents −> db.returnResultOfIncementDemo.insertOne({"PlayerScore":98}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3c292edc6604c74817cda") }Following is the query to display all documents from a collection with the help of find() method −> db.returnResultOfIncementDemo.find();This will produce the following output −{ "_id" : ObjectId("5cd3c292edc6604c74817cda"), "PlayerScore" : 98 }Following is the query to return result of increment. Here, we have incremented PlayerScore by 2 −> db.returnResultOfIncementDemo.findAndModify({ ...   query:{}, ...   update: { $inc: {PlayerScore: 2 }}, ...   new: true ... });This will produce the following output −{ "_id" : ... Read More

Disable Auto-Resizing for a JTable in Java

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

632 Views

To disable auto resizing for a table in Java, set the setAutoResizeMode() to AUTO_RESIZE_OFF −JTable table = new JTable(tableModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);The following is an example to disable auto resizing for a JTable in Java −package my; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       JFrame frame = new JFrame("Demo");       JPanel panel = new JPanel();       String data[][] = { {"Australia", "5", "1"},          {"US", "10", "2"},          {"Canada", ... Read More

Retrieve Value from a Cell in JTable in Java

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

2K+ Views

To retrieve the value of a cell, use the getValueAt() method. As parameters, set the row and column index value for which you want the cell value −int rIndex = 5; // row index int cIndex = 1; // column index Object ob = table.getValueAt(rIndex, cIndex);Display the cell value in the Console −System.out.println("Value = "+ob);The following is an example to retrieve the value from a cell −Examplepackage my; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       JFrame frame ... Read More

Merge Properties of Two JavaScript Objects Dynamically

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

350 Views

There are two methods to merge properties of javascript objects dynamically. They are1) Object.assign() The Object.assign() method is used to copy the values of all properties from one or more source objects to a target object. It will return the target object.Example-1 Live Demo var target = { a: "ram", b: "rahim" }; var source = { c: "akbar", d: "anthony" }; var returnedTarget = Object.assign(target, source); document.write(JSON.stringify(target)); document.write(JSON.stringify(returnedTarget)); output{"a":"ram", "b":"rahim", "c":"akbar", "d":"anthony"} {"a":"ram", "b":"rahim", "c":"akbar", "d":"anthony"}If the objects have the same keys, ... Read More

Get Primary Key Value from Auto-Generated Keys Using JDBC

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

5K+ Views

If you insert records into a table which contains auto-incremented column, using a Statement or, PreparedStatement objects.You can retrieve the values of that particular column, generated by them object using the getGeneratedKeys() method.ExampleLet us create a table with name sales in MySQL database, with one of the columns as auto-incremented, using CREATE statement as shown below −CREATE TABLE Sales(    ID INT PRIMARY KEY AUTO_INCREMENT,    ProductName VARCHAR (20),    CustomerName VARCHAR (20),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(20) );Retrieving auto-generated values (PreparedStatement object)Following JDBC program inserts 3 records into the Sales table (created above) ... Read More

Advertisements