MySQL Articles

Page 290 of 355

Write an JDBC example for inserting value for Clob data type into a table?

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 2K+ Views

Assume we already have a table named MyData in the database with the following description.+---------+--------------+------+-----+---------+-------+ | Field   | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | Name | varchar(255) | YES | | NULL | | | Article | longtext | YES | | NULL | | +---------+--------------+------+-----+---------+-------+If you need to insert ...

Read More

How to fix poor performance of INFORMATION_SCHEMA.key_column_usage in MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 229 Views

You can use GLOBAL variable as shown below −SET global innodb_stats_on_metadata =0;After including the above syntax, the INFORMATION_SCHEMA.key_column_usage will take less time and that would improve the performance.The query is as follows −mysql> set global innodb_stats_on_metadata =0; Query OK, 0 rows affected (0.00 sec) mysql> SELECT REFERENCED_TABLE_NAME,TABLE_NAME,COLUMN_NAME,CONSTRAINT_SCHEMA -> FROM INFORMATION_SCHEMA.key_column_usage;The following is the output −It returns 674 rows in 0.28 seconds.

Read More

Write an JDBC example to retrieve Clob value from a table using the getCharacterStream() method?

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 789 Views

The ResultSet interface provides the method named getClob() to retrieve clob datatype from a table in a database. In addition to this it also provides a method named getCharacterStream()Like getClob() this method also accepts an integer representing the index of the column (or, a String value representing the name of the column) and retrieves the value at the specified column. The difference is unlike the getClob() method (which returns a Clob object) this method returns an object of the Reader class.ExampleAssume we have created a table named MyData in the database with the following description.+---------+--------------+------+-----+---------+-------+ | Field   | Type ...

Read More

How to insert a row into a table that has only a single autoincrement column?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 500 Views

You can easily insert a row into a table that has only a single auto increment column. The syntax is as follows −insert into yourTableName set yourColumnName =NULL;You can use the below syntax −insert into yourTableName values(NULL);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table singleAutoIncrementColumnDemo    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into singleAutoIncrementColumnDemo set UserId ...

Read More

How do we insert/store a file into MySQL database using JDBC?

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 5K+ Views

In general, the contents of a file are stored under Clob (TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT) datatype in MySQL database.JDBC provides support for the Clob datatype, to store the contents of a file in to a table in a database.The setCharacterStream() method of the PreparedStatement interface accepts an integer representing the index of the parameter and, a Reader object as a parameter.And sets the contents of the given reader object (file) as value to the parameter (place holder) in the specified index.Whenever you need to send very large text value you can use this method.Storing text file using JDBC:If you need to ...

Read More

Correctly implement the AND condition in MySQL

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 145 Views

To implement AND condition, the syntax is as follows −select *from yourTableName where yourColumnName1 = yourValue1 AND yourColumnName2 = yourValue2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table MySQLANDConditionDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100),    -> Age int    -> ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into MySQLANDConditionDemo(Name, Age) values('Larry', 23); Query OK, 1 row affected (0.11 sec) mysql> ...

Read More

What does % stand for in host column and how to change user's password?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 417 Views

The localhost means you can access from same machine while from % the remote host access is possible. The syntax is as follows to change the user password.SET PASSWORD FOR 'yourUserName'@'localhost' ='yourPassword';First check the user and host from MySQL.user table. The query is as follows −mysql> select user, host from MySQL.user;Here is the output −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %       | | Manish | % ...

Read More

What is the return type of a “count” query against MySQL using Java JDBC?

George John
George John
Updated on 30-Jul-2019 544 Views

The return type of count is long. The Java statement is as followsrs.next(); long result= rs.getLong("anyAliasName");First, create a table with some records in our sample database test3. The query to create a table is as followsmysql> create table CountDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into CountDemo(Name) values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into CountDemo(Name) values('Carol'); Query OK, 1 row affected (0.16 sec) ...

Read More

What is the smallest datatype for one bit in MySQL?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 222 Views

The smallest datatype for one bit can be bit(1). The syntax is as follows −yourColumnName bit(1)To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table bitDemo    -> (    -> isValid bit(1)    -> ); Query OK, 0 rows affected (0.49 sec)Now you can check all the details of table with the help of SHOW CREATE command. The query is as follows −mysql> show create table bitDemo;Here is the output −+---------+-----------------------------------------------------------------------------------------------------------------------------+ | Table   | Create Table   ...

Read More

How to avoid null result of “SELECT max(rank) FROM test” for an empty table?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 3K+ Views

You can use COALESCE() along with aggregate function MAX() for this.The syntax is as followsSELECT COALESCE(MAX(`yourColumnName`), 0) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table avoidNullDemo    -> (    -> `rank` int    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into avoidNullDemo values(10); Query OK, 1 row affected (0.20 sec) mysql> insert into avoidNullDemo values(NULL); Query OK, 1 row affected (0.18 sec) mysql> insert into avoidNullDemo values(20); Query OK, 1 ...

Read More
Showing 2891–2900 of 3,543 articles
« Prev 1 288 289 290 291 292 355 Next »
Advertisements