473,511 Members | 14,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create DataBase in java

6 New Member
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?
Nov 10 '07 #1
10 3119
r035198x
13,262 MVP
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?
It'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 ...
Nov 10 '07 #2
minakari
6 New Member
It'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?
Nov 10 '07 #3
r035198x
13,262 MVP
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?
So 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?
Nov 10 '07 #4
minakari
6 New Member
So 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?
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.
Nov 10 '07 #5
r035198x
13,262 MVP
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.
You 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?
Nov 10 '07 #6
minakari
6 New Member
You 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_AUTO_VALUE_ON_ZERO";

--
-- 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_username` (`username`,`authority`),
KEY `fk_authorities_users` (`username`),
KEY `dd` (`authority`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `authorities`
--


-- --------------------------------------------------------

--
-- Table structure for table `component_permission`
--

DROP TABLE IF EXISTS `component_permission`;
CREATE TABLE IF NOT EXISTS `component_permission` (
`ID` int(11) NOT NULL auto_increment,
`CompName` varchar(250) NOT NULL default '',
`CompPath` text,
`CopmIfNotGranted` varchar(250) default '',
`CopmIfAnyGranted` varchar(250) default '',
`CopmIfAllGranted` varchar(250) default '',
`CopmDescription` text,
`type` varchar(50) NOT NULL default 'DB',
PRIMARY KEY (`ID`),
UNIQUE KEY `CompName` (`CompName`,`type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;

--
-- Dumping data for table `component_permission`
--


-- --------------------------------------------------------

--
-- 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_unicode_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 `FKC442ABEA7AB9F3E0` (`uid`),
KEY `FKC442ABEA1E53E5F5` (`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_persian_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,
`filterDescription` varchar(100) default NULL,
`filterType` bigint(20) default NULL,
PRIMARY KEY (`uid`),
KEY `FKBB1285B0EFEB0934` (`filterType`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `userfilters`
--


-- --------------------------------------------------------

--
-- Table structure for table `userfiltertypes`
--

DROP TABLE IF EXISTS `userfiltertypes`;
CREATE TABLE IF NOT EXISTS `userfiltertypes` (
`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 `userfiltertypes`
--


-- --------------------------------------------------------

--
-- 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`,`filter_id`),
KEY `FK28003B8771F31D9F` (`user_id`),
KEY `FK28003B87DFFF4E6A` (`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 `fkc442abea1e53e5f5` FOREIGN KEY (`theme_id`) REFERENCES `themes` (`uid`),
ADD CONSTRAINT `fkc442abea7ab9f3e0` FOREIGN KEY (`uid`) REFERENCES `transusers` (`uid`);

--
-- Constraints for table `userfilters`
--
ALTER TABLE `userfilters`
ADD CONSTRAINT `fkbb1285b0efeb0934` FOREIGN KEY (`filterType`) REFERENCES `userfiltertypes` (`uid`);

--
-- Constraints for table `user_filters`
--
ALTER TABLE `user_filters`
ADD CONSTRAINT `fk28003b8771f31d9f` FOREIGN KEY (`user_id`) REFERENCES `transusers` (`uid`),
ADD CONSTRAINT `fk28003b87dfff4e6a` FOREIGN KEY (`filter_id`) REFERENCES `userfilters` (`uid`);
Nov 10 '07 #7
minakari
6 New Member
You 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.
Nov 10 '07 #8
dav3
94 New Member
CLICK HERE

This website might help. I used this authors example as a base when creating my JDBC project.
Nov 10 '07 #9
heat84
118 New Member
Perhaps formating the text and reading each query from file will help. Learn more about reading from file.
Nov 13 '07 #10
r035198x
13,262 MVP
Perhaps formating the text and reading each query from file will help. Learn more about reading from file.
For backup and restoring a mysql database simply use Runtime.exec and pass it the appropriate commands
i.e for backup
Expand|Select|Wrap|Line Numbers
  1.  mysqldump -u yourUserName -pyourPassword yourDB > filename.sql
and

Expand|Select|Wrap|Line Numbers
  1.  mysql -u yourUserName -pyourPassword yourDB < filename.sql
for restoring
Nov 13 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
13559
by: Jim Garrison | last post by:
I need to create a ResultSet in an Oracle Java Stored Procedure and return it to a PL/SQL caller. I've done quite a bit of research in Oracle's manuals and on the Web, and have found lots of...
1
2612
by: D. Lee Christopher | last post by:
Can anyone point me to a good tutorial for creating a site-level search applet? I am trying to create a virtual catalog of sorts, and I would like to be able to search the catalog and have the...
62
4052
by: SAN3141 | last post by:
There doesn't seem to be consensus about when to put code in the database or in the middle tier. There was a long discussion about this in an Oracle newsgroup (message ID:...
6
7304
by: Marvin Libson | last post by:
Hi All: I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I have created a java UDF and trigger. When I update my database I get the following error: SQL1224N A database...
5
14688
by: Hassan Naqvi | last post by:
Hi, Basically, I am Java developer. In past I have played with Oracle using Java (JDBC). But this is the time to play with IBM DB2 using Java (JDBC). So kindly help this DB2 newbie. I have a...
9
3536
by: Albretch | last post by:
.. I am trying to create a database in a MS Access DB via JDBC drivers. I have tried both sun.jdbc.odbc.JdbcOdbcDriver and ids.sql.IDSDriver From some reason both drivers Exceptions tell me...
1
2714
by: ravikiranveluguleti | last post by:
hi, this is ravikiran, I have a situation where i need to create an ms-access database with one table in it at runtime when an user clicks on a button in my front end. Is there any way to...
0
1100
by: shweta gandhi | last post by:
hi, ]Someone know how to create database dyndmically in postgreSQL through Java code? How to check particular database exist or not in postgreSQL through java code? such as we can see in sql server...
1
4441
by: henrymania | last post by:
Am writing a code for database backup....by backupservlet is as given below i get the following exception
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.