I have a sql file ,how can I create DataBase in java I mean how can I restore my sql script with java code,isther any sample?
create DataBase in java
Collapse
X
-
It's not yet clear (to me at least) what you really want to do.Originally posted by minakariI have a sql file ,how can I create DataBase in java I mean how can I restore my sql script with java code,isther any sample?
By sql script do you mean a file that contains sql code?
And what do you mean by "restore my sql script"? Perhaps if you try to explain this again ... -
Originally posted by r035198xIt's not yet clear (to me at least) what you really want to do.
By sql script do you mean a file that contains sql code?
And what do you mean by "restore my sql script"? Perhaps if you try to explain this again ...
I hava a file that contains sql code,and I want use this file for create DataBase,but I dont now How can I do this in java?Comment
-
So this file contains sql commands for creating a database? Does it have one sql commands or does it have many sql commands?Originally posted by minakariI hava a file that contains sql code,and I want use this file for create DataBase,but I dont now How can I do this in java?
Which database are you using(MySQL, Oracle, e.t.c)?
Do you know how to use JDBC?Comment
-
this file has many sql commands,and DataBase Mysql or sq Server Or ...because I read connection information from a property file and the type of my Database isspecified in that file,because my application can connect to diffrent databases.Originally posted by r035198xSo this file contains sql commands for creating a database? Does it have one sql commands or does it have many sql commands?
Which database are you using(MySQL, Oracle, e.t.c)?
Do you know how to use JDBC?Comment
-
You could read each command one by one and execute them.Originally posted by minakarithis file has many sql commands,and DataBase Mysql or sq Server Or ...because I read connection information from a property file and the type of my Database isspecified in that file,because my application can connect to diffrent databases.
Do you know how to read a file using using a FileReader? How are your sql commands separated?Comment
-
Originally posted by r035198xYou could read each command one by one and execute them.
Do you know how to read a file using using a FileReader? How are your sql commands separated?
This is my sql file that I creat it by backup from my DataBase and I use MYSQL:
-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin. net
--
-- Host: 172.25.1.220
-- Generation Time: Nov 05, 2007 at 04:08 PM
-- Server version: 5.0.22
-- PHP Version: 5.1.6
SET SQL_MODE="NO_AU TO_VALUE_ON_ZER O";
--
-- Database: `mpa`
--
-- --------------------------------------------------------
--
-- Table structure for table `authorities`
--
DROP TABLE IF EXISTS `authorities`;
CREATE TABLE IF NOT EXISTS `authorities` (
`username` varchar(50) NOT NULL default '',
`authority` varchar(50) NOT NULL default '',
UNIQUE KEY `ix_auth_userna me` (`username`,`au thority`),
KEY `fk_authorities _users` (`username`),
KEY `dd` (`authority`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `authorities`
--
-- --------------------------------------------------------
--
-- Table structure for table `component_perm ission`
--
DROP TABLE IF EXISTS `component_perm ission`;
CREATE TABLE IF NOT EXISTS `component_perm ission` (
`ID` int(11) NOT NULL auto_increment,
`CompName` varchar(250) NOT NULL default '',
`CompPath` text,
`CopmIfNotGrant ed` varchar(250) default '',
`CopmIfAnyGrant ed` varchar(250) default '',
`CopmIfAllGrant ed` varchar(250) default '',
`CopmDescriptio n` text,
`type` varchar(50) NOT NULL default 'DB',
PRIMARY KEY (`ID`),
UNIQUE KEY `CompName` (`CompName`,`ty pe`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT= 15 ;
--
-- Dumping data for table `component_perm ission`
--
-- --------------------------------------------------------
--
-- Table structure for table `favorits`
--
DROP TABLE IF EXISTS `favorits`;
CREATE TABLE IF NOT EXISTS `favorits` (
`uid` bigint(20) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`uri` varchar(250) default NULL,
`userId` varchar(100) default NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT= 8 ;
--
-- Dumping data for table `favorits`
--
-- --------------------------------------------------------
--
-- Table structure for table `menu`
--
DROP TABLE IF EXISTS `menu`;
CREATE TABLE IF NOT EXISTS `menu` (
`id` int(11) NOT NULL auto_increment,
`url` text character set latin1 NOT NULL,
`parent_id` int(11) default '0',
`name` text character set utf8 collate utf8_swedish_ci NOT NULL,
`roles` text character set latin1 NOT NULL,
`sequence` int(11) default '0',
`type` varchar(25) character set latin1 NOT NULL default 'DB',
`description` text character set utf8 collate utf8_swedish_ci ,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_un icode_ci AUTO_INCREMENT= 27 ;
--
-- Dumping data for table `menu`
--
-- --------------------------------------------------------
--
-- Table structure for table `profiles`
--
DROP TABLE IF EXISTS `profiles`;
CREATE TABLE IF NOT EXISTS `profiles` (
`uid` bigint(20) NOT NULL,
`theme_id` bigint(20) default NULL,
PRIMARY KEY (`uid`),
KEY `FKC442ABEA7AB9 F3E0` (`uid`),
KEY `FKC442ABEA1E53 E5F5` (`theme_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `profiles`
--
-- --------------------------------------------------------
--
-- Table structure for table `related_menu`
--
DROP TABLE IF EXISTS `related_menu`;
CREATE TABLE IF NOT EXISTS `related_menu` (
`id` bigint(20) NOT NULL auto_increment,
`url` int(11) NOT NULL,
`relatedurl` text collate utf8_persian_ci NOT NULL,
`roles` text collate utf8_persian_ci NOT NULL,
`type` varchar(25) collate utf8_persian_ci NOT NULL,
`description` text collate utf8_persian_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_pe rsian_ci AUTO_INCREMENT= 7 ;
--
-- Dumping data for table `related_menu`
--
-- --------------------------------------------------------
--
-- Table structure for table `roles`
--
DROP TABLE IF EXISTS `roles`;
CREATE TABLE IF NOT EXISTS `roles` (
`role_name` varchar(50) NOT NULL,
PRIMARY KEY (`role_name`),
UNIQUE KEY `role_name` (`role_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `roles`
--
-- --------------------------------------------------------
--
-- Table structure for table `themes`
--
DROP TABLE IF EXISTS `themes`;
CREATE TABLE IF NOT EXISTS `themes` (
`uid` bigint(20) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`description` varchar(100) default NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT= 3 ;
--
-- Dumping data for table `themes`
--
-- --------------------------------------------------------
--
-- Table structure for table `transusers`
--
DROP TABLE IF EXISTS `transusers`;
CREATE TABLE IF NOT EXISTS `transusers` (
`uid` bigint(20) NOT NULL auto_increment,
`userId` varchar(30) default NULL,
`name` varchar(100) default NULL,
`activated` tinyint(3) unsigned default NULL,
`creatingUser` varchar(255) default NULL,
`creatingDate` varchar(255) default NULL,
`creatingTime` varchar(255) default NULL,
`updatingUser` varchar(255) default NULL,
`updatingDate` varchar(255) default NULL,
`updatingTime` varchar(255) default NULL,
`deletingUser` varchar(255) default NULL,
`deletingDate` varchar(255) default NULL,
`deletingTime` varchar(255) default NULL,
`deleted` tinyint(3) unsigned default NULL,
`workGroup` varchar(255) default NULL,
PRIMARY KEY (`uid`),
UNIQUE KEY `userId` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT= 18 ;
--
-- Dumping data for table `transusers`
--
-- --------------------------------------------------------
--
-- Table structure for table `url_permission `
--
DROP TABLE IF EXISTS `url_permission `;
CREATE TABLE IF NOT EXISTS `url_permission ` (
`ID` bigint(20) NOT NULL auto_increment,
`name` varchar(256) NOT NULL,
`roles` text NOT NULL,
`description` text,
`type` varchar(25) NOT NULL default 'DB',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT= 121 ;
--
-- Dumping data for table `url_permission `
--
-- --------------------------------------------------------
--
-- Table structure for table `userfilters`
--
DROP TABLE IF EXISTS `userfilters`;
CREATE TABLE IF NOT EXISTS `userfilters` (
`uid` bigint(20) NOT NULL auto_increment,
`filterName` varchar(25) default NULL,
`filterDescript ion` varchar(100) default NULL,
`filterType` bigint(20) default NULL,
PRIMARY KEY (`uid`),
KEY `FKBB1285B0EFEB 0934` (`filterType`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT= 6 ;
--
-- Dumping data for table `userfilters`
--
-- --------------------------------------------------------
--
-- Table structure for table `userfiltertype s`
--
DROP TABLE IF EXISTS `userfiltertype s`;
CREATE TABLE IF NOT EXISTS `userfiltertype s` (
`uid` bigint(20) NOT NULL auto_increment,
`filterTypeName ` varchar(30) default NULL,
`description` varchar(100) default NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT= 2 ;
--
-- Dumping data for table `userfiltertype s`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL default '',
`enabled` bit(1) NOT NULL default '\0',
PRIMARY KEY (`username`),
UNIQUE KEY `primerykey` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `users`
--
-- --------------------------------------------------------
--
-- Table structure for table `user_filters`
--
DROP TABLE IF EXISTS `user_filters`;
CREATE TABLE IF NOT EXISTS `user_filters` (
`user_id` bigint(20) NOT NULL,
`filter_id` bigint(20) NOT NULL,
PRIMARY KEY (`user_id`,`fil ter_id`),
KEY `FK28003B8771F3 1D9F` (`user_id`),
KEY `FK28003B87DFFF 4E6A` (`filter_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `user_filters`
--
--
-- Constraints for dumped tables
--
--
-- Constraints for table `profiles`
--
ALTER TABLE `profiles`
ADD CONSTRAINT `fkc442abea1e53 e5f5` FOREIGN KEY (`theme_id`) REFERENCES `themes` (`uid`),
ADD CONSTRAINT `fkc442abea7ab9 f3e0` FOREIGN KEY (`uid`) REFERENCES `transusers` (`uid`);
--
-- Constraints for table `userfilters`
--
ALTER TABLE `userfilters`
ADD CONSTRAINT `fkbb1285b0efeb 0934` FOREIGN KEY (`filterType`) REFERENCES `userfiltertype s` (`uid`);
--
-- Constraints for table `user_filters`
--
ALTER TABLE `user_filters`
ADD CONSTRAINT `fk28003b8771f3 1d9f` FOREIGN KEY (`user_id`) REFERENCES `transusers` (`uid`),
ADD CONSTRAINT `fk28003b87dfff 4e6a` FOREIGN KEY (`filter_id`) REFERENCES `userfilters` (`uid`);Comment
-
Originally posted by r035198xYou could read each command one by one and execute them.
Do you know how to read a file using using a FileReader? How are your sql commands separated?
I have backed up from my database and my back up file name is MPA.sql ,now I want create a new database with the name MPA2 ,so I want use MPA.sql in my java code and create my new database that this data base is exactly like the first database ,I DONT NOW HOW DO THAT ,is ther any sample ,can u help me?
could u anderstand my prolem?plz help me as it possible.Comment
-
CLICK HERE
This website might help. I used this authors example as a base when creating my JDBC project.Comment
-
For backup and restoring a mysql database simply use Runtime.exec and pass it the appropriate commandsOriginally posted by heat84Perhaps formating the text and reading each query from file will help. Learn more about reading from file.
i.e for backup
[CODE=mysql] mysqldump -u yourUserName -pyourPassword yourDB > filename.sql[/CODE]
and
[CODE=mysql] mysql -u yourUserName -pyourPassword yourDB < filename.sql[/CODE]
for restoringComment
Comment