473,671 Members | 2,221 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 3134
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_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`);
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

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

Similar topics

3
13573
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 references to going the other direction (PL/SQL passing/returning REF CURSOR to Java), and Java returning an existing ResultSet (obtained from the databse) as a REF CURSOR to PL/SQL. Neither of these is what I'm looking for. My Java stored...
1
2628
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 results displayed on the same page with one column text and an image of the product. I've seen several tutorials that create site-level searches that will bring back a search results page with options to choose from. I am looking to create a...
62
4096
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: ULcQb.466$KU5.37@nwrddc02.gnilink.net). Elsewhere there's been discussion about Microsoft SQL Server 2005 adding the CLR to support stored procedures in languages such as C#. A scan of the Web and discussion forums finds differing opinions about this.
6
7335
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 agent could not be started to service a request, or was terminated as a result of a database system shutdown or a force command.
5
14704
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 file of 32 MB, named as "fdbk5.0". This is actually a database created in DB2 and containing records. I am interested in viewing the *structure of this database, i.e. table names, column names and finally all the records. How I can do this? Which...
9
3549
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 'Syntax error in CREATE TABLE statement' even though I am not creating a table, but a Database // - - - - - - - - - - - - sun.jdbc.odbc.JdbcOdbc aSQL=CREATE DATABASE dbtest; java.sql.SQLException:
1
2727
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 create a new database at runtime in ms-access using java. plz help me thanx in advance
0
1110
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 in system obj all the created databases & tables!!
1
4456
by: henrymania | last post by:
Am writing a code for database backup....by backupservlet is as given below i get the following exception
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6229
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
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 we have to send another system

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.