Get Database Product Name Using DatabaseMetaData in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

1K+ Views

The getDatabaseProductName() method of the DatabaseMetaData interface returns the name of the underlying database in String format.To know the name of the underlying database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData object with respect to the current connection using the getMetaData() method of the Connection interface.Finally ... Read More

Set Font and Color of Text in JTextPane Using Styles

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

3K+ Views

Let’s say the following is our JTextPane −JTextPane textPane = new JTextPane();Now, set the font style for some of the text −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setItalic(attributeSet, true); textPane.setCharacterAttributes(attributeSet, true); textPane.setText("Learn with Text and ");For rest of the text, set different color −StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("", null); StyleConstants.setForeground(style, Color.orange); StyleConstants.setBackground(style, Color.black); doc.insertString(doc.getLength(), "Video Tutorials ", style);The following is an example to set font and text color in a JTextPane with Styles −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import ... Read More

Get the Average of Marks in MongoDB with Aggregate

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

512 Views

Use $avg operator along with aggregate framework. Let us first create a collection with documents. Here, one of the fields is StudentScore −> db.averageReturiningNullDemo.insertOne(    {"StudentDetails" : { "StudentScore" : 89 } }); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce9822e78f00858fb12e927") } > db.averageReturiningNullDemo.insertOne(    {"StudentDetails" : { "StudentScore" : 34 } }); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce9822e78f00858fb12e928") } > db.averageReturiningNullDemo.insertOne(    {"StudentDetails" : { "StudentScore" : 78 } }); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce9822e78f00858fb12e929") }Following is the query to display all documents from a collection with the help of find() ... Read More

HTML defaultPrevented Event Property

Chandu yadav
Updated on 30-Jul-2019 22:30:26

184 Views

The defaultPrevented event property in HTML is used to check whether the preventDefault() method was called or not. It returns a boolean value i.e. true if the preventDefault() method was called, else false.Following is the syntax −event.defaultPreventedLet us now see an example to implement the defaultPrevented event property in HTML −Example Live Demo Demo Heading Demo (click me)    document.getElementById("myid").addEventListener("click", function(event){       event.preventDefault()       alert("Was preventDefault() called: " + event.defaultPrevented);    }); OutputClick on the link and the following would get displayed in the alert box −

Extract Area Codes from Phone Number with MySQL

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

1K+ Views

Let’s say we have a list of phone numbers and from that we want to get the area codes. These area codes are for example, the first 3 digits of the phone number. Use LEFT() function from MySQL for this.Let us first create a table −mysql> create table DemoTable -> ( -> AreaCodes varchar(100) -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. Here, let’s say we have included the phone numbers −mysql> insert into DemoTable values('90387568976') ; Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('90389097878' ; ... Read More

Select Last Day of Current Year in MySQL

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

1K+ Views

In order to get last day of current year, you can use LAST_DAY() from MySQL. The syntax is as follows−SELECT LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 12-MONTH(CURDATE()) MONTH));Let us implement the above syntax to know the last day of current year−mysql> SELECT LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 12-MONTH(CURDATE()) MONTH));This will produce the following output −+-------------------------------------------------------------------+ | LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 12-MONTH(CURDATE()) MONTH)) | +-------------------------------------------------------------------+ | 2019-12-31 | +-------------------------------------------------------------------+ 1 row in set (0.00 sec)

Difference Between a Blockchain and a Database

Prasanna Kotamraju
Updated on 30-Jul-2019 22:30:26

297 Views

The difference between a Block chain and a traditional database begins with architecture, creation, access, and permissions. They differ in each and every aspect except that they both are huge repositories of data which is stored and accessed in an organised form, digitally.DatabaseThis runs on a client-server network, where there is a central repository of data that will be accessed by those nodes who have permission to access the data. The data of the database is maintained by administrators, and mostly nodes will have access to retrieve the data as per their requirement.Database, which is an electronic collection of data ... Read More

Create a Number Spinner in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:26

446 Views

At first, create a SpinnerModel −SpinnerModel value = new SpinnerNumberModel(50, 0, 75, 1);Now, set the values −JSpinner spinner = new JSpinner(value);The following is an example to create a number spinner −Examplepackage my; import javax.swing.*; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Spinner Demo");       SpinnerModel value = new SpinnerNumberModel(50, 0, 75, 1);       JSpinner spinner = new JSpinner(value);       spinner.setBounds(50, 80, 70, 100);       frame.add(spinner);       frame.setSize(550,300);       frame.setLayout(null);       frame.setVisible(true);    } }This will produce the following output −

Filter by Several Array Elements in MongoDB

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

214 Views

For this, you can use $elemMatch operator. The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. Let us first create a collection with documents −> db.filterBySeveralElementsDemo.insertOne(    "_id":100,    "StudentDetails": [       {          "StudentName": "John",          "StudentCountryName": "US",       },       {          "StudentName": "Carol",          "StudentCountryName": "UK"       }    ] } ); { "acknowledged" : true, "insertedId" : 100 } > db.filterBySeveralElementsDemo.insertOne(    { ... Read More

Best Data Type for Storing Large Strings in MySQL

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

936 Views

You can use text data type to store large strings. Following is the syntax −CREATE TABLE yourTableName (    yourColumnName text,    .    .    N );Let us first create a table −mysql> create table DemoTable -> ( -> MyStringValue text -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('This is a text data type to store large string'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from ... Read More

Advertisements