Found 33676 Articles for Programming

How to convert a timestamp object in to Date in JDBC program?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

622 Views

The getTime() method of the Timestamp class retrieves and returns the time from the current timestamp in milliseconds (long) from epoch time 1, 1970 00:00:00.000 GMT.Timestamp timestamp = rs.getTimestamp("DispatTimestamp"); long time = timestamp.getTime();The constructor of the java.sql.Date class accepts a long variable representing the time in milliseconds from the epoch time and constructs the date object.//Printing the date of dispatch System.out.println("Date of dispatch: "+new Date(time));Using these, you can convert a TimeStamp object to Date object in JDBC.Assume we have established connection with MySQL database and created a table named dispatch_data using statement object as://Creating a Statement object Statement stmt = ... Read More

Single quotes vs. double quotes in C or C++

Revathi Satya Kondra
Updated on 17-Apr-2025 18:00:27

8K+ Views

When coding in C/C++, we go across single quotes (' ') and double quotes (" "). These symbols have different roles in the language. Single quotes stand for single characters, while double quotes define strings, which are groups of characters. Knowing this difference has an impact on how data gets stored compared, and handled in your code. So, let us explore various approaches regarding single vs double quotes in C/C++. Character vs String Representation Memory and Size Difference Comparison Behavior Function Call Behavior ... Read More

How to get the row count in JDBC?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

7K+ Views

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Suppose we have established a connection with MySQL and created a table in the database named mydatabase using Statement object as://Creating the Statement object Statement stmt = con.createStatement(); //Query to create a table String query = "CREATE TABLE Cricketers_Data( "    + "First_Name VARCHAR(255), "    + "Last_Name VARCHAR(255), "    + "Date_Of_Birth Date, "    + "Place_Of_Birth VARCHAR(255), "    + "Country VARCHAR(255))"; //Executing the query stmt.execute(query); System.out.println("Table created......");In to this table we ... Read More

C++ Program to Print the Kind of Rotation the AVL Tree is Undergoing When you Add an Element or Delete an Element

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

142 Views

AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodesTree rotation is an operation that changes the structure without interfering with the order of the elements on an AVL tree. It moves one node up in the tree and one node down. It is used to change the shape of the tree, and to decrease its height by moving smaller subtrees down and larger subtrees up, resulting in improved performance of many tree operations. The direction of a rotation depends on the side which ... Read More

Why use static_cast(x) instead of (int)x in C++?

Revathi Satya Kondra
Updated on 17-Apr-2025 18:01:00

2K+ Views

The (int)x is C-style typecasting, where static_cast(x) is used in C++. This static_cast() gives a compile-time checking facility, but the C-style casting does not support that. This static_cast() can be spotted anywhere inside a C++ code. And using this C++ cast, the intentions are conveyed much better. In C like cast, sometimes we can cast some type pointer to a point some other type data. Like one integer pointer can also point character type data, as they are quite similar, the only difference is character has 1-byte, integer has 4-bytes. In C++, the static_cast() is more strict than C-like casting. ... Read More

Why is it considered a bad practice to omit curly braces in C/C++?

Revathi Satya Kondra
Updated on 11-Apr-2025 17:32:54

1K+ Views

In C/C++, omitting the curly braces assumes that only the first statement is the block and this leads to quite a few issues during debugging, as code is pretty tough to read and comprehend. Curly braces help us prevent errors and confusion, which also helps with the flow of the program. Proper Use of Curly Braces In C++, we can omit the curly braces after if-else statements, or after any loop. If we do not use curly braces, then only one statement after the if-else or loop will be considered under that block. Syntax The following is the syntax: − ... Read More

How to connect to Derby database using a JDBC program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

2K+ Views

Apache Derby is a Relational Database Management System which is fully based on (written/implemented in) Java programming language. It is an open source database developed by Apache Software Foundation.Installing derby:Follow the steps given below to install derby:Visit the home page of Apache Derby home page https://db.apache.org/derby/. Click the Download tab.Select and click on the link of the latest version of Apache Derby.On clicking the selected link, you will be redirected to the Distributions page of apache derby. If you observe here, derby provides distributions namely, db-derby-bin, db-derbylib.zip, db-derby-lib-debug.zip, and db-derby-src.zip.Download the db-derby-bin folder. Copy its contents to a separate folder ... Read More

Understanding cin.clear() and cin.ignore() in C++

Revathi Satya Kondra
Updated on 11-Apr-2025 17:33:40

1K+ Views

When we attempt to work with user input in C++, unwanted behavior may be caused by errors or leftover characters in the input buffer. So, in that case cin.clear() and cin.ignore() are functions that can help in dealing with this kind of problem. cin.clear() cin.ignore() cin.clear and cin.ignore() cin.clear() The cin.clear() resets the error flags on the cin stream and is used when an input operation fails (e.g., entering a non-numeric value for an integer variable). Without clearing the error flags, further input operations will not work. ... Read More

How to connect to an SQLite database using a JDBC program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

2K+ Views

A. SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. It is a database, which is zero-configured, which means like other databases you do not need to configure it in your system.SQLite engine is not a standalone process like other databases, you can link it statically or dynamically as per your requirement with your application. SQLite accesses its storage files directly.The URL to connect with SQLite database is jdbc:sqlite:test.db and, the driver class name to connect to it is org.sqlite.JDBC.Before you proceed with the example:Download latest version of sqlite-jdbc-(VERSION).jar from sqlite-jdbcrepository.Add downloaded jar file ... Read More

C++ Program to Print only Odd Numbered Levels of a Tree

Revathi Satya Kondra
Updated on 11-Apr-2025 17:32:01

228 Views

In C++, to print the odd-numbered levels of a binary tree, the levels are numbered from the root as Level 1. The odd-numbered levels are Level 1, Level 3, and so on. This program prints the nodes present at these odd levels. It uses level-order traversal to process the tree level by level and prints the nodes found at these levels. Algorithm to Print only Odd Numbered Levels of a Tree Following is the Algorithm to print odd numbered levels of a tree − Create a structure for tree nodes with data and pointers to left ... Read More

Advertisements