Anvi Jain

Anvi Jain

427 Articles Published

Articles by Anvi Jain

Page 23 of 43

What is the MySQL datatype to store DATALINK object in JDBC

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 463 Views

A DATALINK object represents an URL value which refers to an external resource (outside the current database/data source), which can be a file, directory etc..MySQL does not provide any separate datatype to store DATALINK/URL value you need to store using TEXT or VARCHAR datatypes as shown in the following query −CREATE TABLE tutorials_data (    tutorial_id INT PRIMARY KEY AUTO_INCREMENT,    tutorial_title VARCHAR(100),    tutorial_author VARCHAR(40),    submission_date date,    tutorial_link VARCHAR(255) );Following JDBC program establishes a connection with MYSQL database, creates a table with name tutorials_data. In this table we are creating a column with name tutorial_link which stores ...

Read More

How to retrieve binary data from a table using JDBC?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 1K+ Views

SQL databases provide a datatype named Blob (Binary Large Object) in this, you can store large binary data like images.To retrieve binary (stream) values from a table JDBC provides a method called getBinaryStream() in the PreparedStatement interface.It accepts an integer representing the index of the column of the table and retrieves the binary data from it.You can retrieve binary data from a table using this method as shown below −FileInputStream fin = new FileInputStream("javafx_logo.jpg"); pstmt.setBinaryStream(3, fin);ExampleLet us create a table with name tutorials_data in MySQL using the CREATE statement as shown below −CREATE TABLE tutorials_data(    Name VARCHAR(255),    Type ...

Read More

What is the Java equivalent to MySQL's smallint?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

The short is equivalent to MySQL’s small int. The Java short takes 2 bytes that has the range -32768 to 32767 while MySQL smallint also take 2 bytes with same range.Here is the demo code of short in Java −public class SmallIntAsShortDemo {    public static void main(String[] args) {       short value = 32767;       System.out.println(value);       value = -32768;       System.out.println(value);       // value = 32768;       // System.out.println(value);    } }The snapshot is as follows −This will produce the following output −32767 -32768Here is the snapshot of the output we ran in EclipseIDE −The MySQL smallint takes 2 bytes with same range.

Read More

Delete the first 10 characters from JTextArea in Java

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 498 Views

Let’s say the following is our JTextArea with default text −JTextArea textArea = new JTextArea("The text added here is just for demo. "    + "This demonstrates the usage of JTextArea in Java. In this example we have"    + "deleted some text.");Now to remove the first 10 characters, use replaceRange() method and set null from one end to another i.e. deleting characters in a range. The replaceRaneg() method Replaces text from the indicated start to end position with the new text specified i.e.e here null will replace the first 10 characters −int start = 0; int end = 10; ...

Read More

How to Read data from BLOB and CLOB type columns from a table using JDBC?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 6K+ Views

Clob datatypeCLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).Reading Data from a column of datatype ClobYou can read CLOB value (character stream data) from a ...

Read More

How to get the list of all drivers registered with the DriverManager using JDBC?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 1K+ Views

The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.One way to register a driver class object to Driver manager is the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);List of all the DriversYou can get the list of all the drivers registered ...

Read More

Java Program to replace the first 10 characters in JTextArea

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 322 Views

To replace the first 10 character in text area, use the replaceRange() method in Java and replace the old text with the new text.Let’s say the following is oude demo text set with JTextArea −JTextArea textArea = new JTextArea("This is a text displayed for our example. We have replaced some of the text.");Now, replace the characters in a range −int begn = 0; int end = 10; // replace textArea.replaceRange("Replaced! ", begn, end);The following is an example to replace the first 10 charactrers in JTextArea −Examplepackage my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo {    SwingDemo() {     ...

Read More

Perform multiplication in SELECT depending on column value in MySQL?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 784 Views

You can use CASE statement for this. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value1 int,    Value2 int    ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value1, Value2) values(10, 5); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Value1, Value2) values(20, 0); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Value1, Value2) values(40, 10); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(Value1, Value2) ...

Read More

How to make a background 25% transparent on iOS

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 1K+ Views

Apple provides backgroundColor which is an instance property, Changes to this property can be animated. The default value is nil, which results in a transparent background color.To make background 25% transparent we should  set the view to the UIColor with alpha 0.25view.backgroundColor = UIColor(white: 1, alpha: 0.25)You can write the following code in your ViewController’s viewDidLoad method.Your code should look like below.override func viewDidLoad() {    super.viewDidLoad()    view.backgroundColor = UIColor(white: 1, alpha: 0.25) }

Read More

MongoDB query to replace value with aggregation?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 532 Views

Use aggregate framework along with $literal operator. Let us first create a collection with documents −> db.replaceValueDemo.insertOne(    {       _id : 100,       "EmployeeName" :"Chris",       "EmployeeOtherDetails": {          "EmployeeDesignation" : "HR",          "EmployeeAge":27       }    } ); { "acknowledged" : true, "insertedId" : 100 } > db.replaceValueDemo.insertOne(    {       _id : 101,       "EmployeeName" :"David",       "EmployeeOtherDetails": {          "EmployeeDesignation" : "Tester",          "EmployeeAge":26       }    } ...

Read More
Showing 221–230 of 427 articles
« Prev 1 21 22 23 24 25 43 Next »
Advertisements