Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
What is the MySQL datatype to store DATALINK object in JDBC
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 an URL value, for this column, we are using VARCHAR as datatype.
Example
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class CreateTable_Datalink {
public static void main(String args[])throws Exception {
//Registering the Driver
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//Getting the connection
String mysqlUrl = "jdbc:mysql://localhost/sampledatabase";
Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");
System.out.println("Connection established......");
//Creating a Statement object
Statement stmt = con.createStatement();
//Query to create a tutorials_data table
String query = "CREATE TABLE Customers("
+ "ID INT NOT NULL, "
+ "NAME VARCHAR (20) NOT NULL, "
+ "AGE INT NOT NULL, "
+ "SALARY DECIMAL (18, 2), "
+ "ADDRESS VARCHAR (25), "
+ "Date Date, "
+ "PRIMARY KEY(ID))";
//Executing the query
stmt.execute(query);
System.out.println("Table created ........");
}
}
Output
Connection established...... Table created ........
Advertisements
