ANT initialization database [actual combat]

xiaoxiao2021-03-06  14

Everyone knows that for a B / S system, it is important to initialize the database. Below is an experience in which I use Ant to initialize data in the database, share it here for everyone.

Prerequisites: Install the MySQL database and Ant, download MySQL JDBC driver, the MySQL database is started, and the path and classpath have been configured.

1. Prepare the files of the database operation.

---- Photo_Manager.sql ----

CREATE DATABASE PHOTO_MANAGER;

USE Photo_Manager;

Create Table News (ID INT NOT NULL AUTO_INCREMENT, TITLE VARCHAR (50) Not NULL, Content Text Not Null, Pub_Time DateTime Not Null, Primary Key (ID));

Create Table Phototype (ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR (50) NULL, DESCRIPTION VARCHAR (100) NULL, PRIMARY Key (ID));

create table photo (id int not null auto_increment, typeid int not null, name varchar (50) not null, image mediumblob not null, upload_time datetime not null, primary key (id), foreign key (typeid) references phototype (id) on Delete Cascade on Update Cascade;

2, ready to be a buildfile file.

---- setUpdb.xml ----

3, execute Ant.

Suppose photo_manager.sql and setupdb.xml stored in a D: / java directory, open the DOS window, switch to D: / java directory,

Perform ant -f setupdb.xml, you can perform the initialization of database data, thank you, welcome to improve advice.

转载请注明原文地址:https://www.9cbs.com/read-49072.html

New Post(0)