Wednesday, March 21, 2012

How to connect to JavaDB and create database -- Tutorial

1. Open your Netbeans, go to Window and select Services. Alternatively press CTRL+5.

2. Right Click on JavaDB and select Start Server

3. Right Click again and this time select Create Databese
  1. name it -- login
  2. username -- nut
  3. password -- nut
  4. confirm password
  5. click OK

4. Right click on jdbc:derby://localhost:1527/login[nut on APP] and select Connect

5. Open jdbc:derby://localhost:1527/login[nut on APP] tree and select APP

6. Right click on Tables, select Create Table


7. Name your table -- users


8. Create columns, one by one
  1. firstName
  2. lastName
  3. userName
  4. password
  5. address1
  6. address2
  7. address3
  8. address4
  9. telephone
  10. mobile
  11. email
  12. ageGroup
  13. employmentStatus

9. Alternatively you can create and populate your table using mysql query. Right click on Tables and select Execute Command and insert following mySql query.

CREATE TABLE users (firstName VARCHAR(20), lastName VARCHAR(20), userName VARCHAR(15), password VARCHAR(15), address1 VARCHAR(30), address2 VARCHAR(30), address3 VARCHAR(20), address4 VARCHAR(20), telephone VARCHAR(15), mobile VARCHAR(15), email VARCHAR(35), ageGroup VARCHAR(5), employmentStatus VARCHAR(17));
and  Run SQL.

10. Add some users...
INSERT INTO users 
VALUES      ('Jake', 'Roberts', 'snake@ifpwafcad.com', 'password' , '123 Castle Lawns' , 'Tallagh' , 'Dublin 24' , 'Ireland' , '412 565-5656', '555 565-5656','snake@ifpwafcad.com', '18-24' , 'Student' ),
('Andre','','snake@ifpwafcad.com', 'password' , '123 Castle Lawns' , 'Tallagh' , 'Dublin 24' , 'Ireland' , '412 565-5656', '555 565-5656','snake@ifpwafcad.com', '18-24' , 'Student' );
and  Run SQL.



No comments:

Post a Comment