Google Search

Tuesday, April 5, 2011

JDBC connection with mysql

Hello Friend, Today I am writing about COMPLETE DATABASE CONNECTIVITY IN JAVA. The reason behind writing on this topic is it's very difficult to find help on this topic and if we found it's in pieces, because there is no help for complete database connectivity. Even in books JDBC topic is quite hazy. So here I am throwing some light on this topic :-). For convenience post is divided into three parts :- Installing and configuring MySql. Installing and configuring JDBC Driver (Connector/J in this example) Java Program to handle and manipulating data Installing and configuring MySql. Download MySql Community Server zip file(without installer) compatible to your windows. Create new folder name it "mysql"(without quotes) Extract the zip file on that folder. Now open your command prompt and go to the mysql directory that you created and then go inside the extracted directory something like(mysql-5.5.8-winx64) then bin. C:\>cd C:\mysql\mysql-5.5.8-winx64\bin Now type command "mysqld"(without quotes) Hit Enter Allow access if firewall is blocking mysqld.exe hence your MySql server starts. Remain this command prompt open and open new Command Prompt and repeat Step 3. again Type mysql -u root C:\mysql\mysql-5.5.8-winx64\bin>mysql - u root Notice you will get the mysql> prompt. Now select database mysql using following command: mysql> use mysql Now change the password of root user for security purpose use following command mysql> UPDATE user SET password = PASSWORD('urpassword') WHERE user = 'root'; Now to delete ghost account use following command: mysql> DELETE FROM user WHERE user = ''; Now just quit from mysql using following command: mysql>quit Your Topic number I is completed let's move to next step(Driver Installation) Installing JDBC driver For JDBC connectivity to MySql we are using Type-4 driver Connector/J Again download the zip file for windows user. Create new folder named as "jdbc"(without quotes) in C:\ and extract the zip file in that folder Now we have to set Classpath to install JDBC Driver Right click on my computer and select properties and Advanced Settings then click to environment variables Now in System variables edit Classpath variable and at the end of it's value there should be semicolon to end the previous path than past your jdbc directory address ends with .jar file driver name and then semicolon in the end. Now save it and your driver is also installed.

Wednesday, March 30, 2011

Login to another user in MySql

Every one knows how to login to mysql server. But few people might not know how to create and login to the new user. Follow these steps

  •  open the installed mysql Server
  •  Enter MySql root password

   
  • Choose any Database using the command SHOW DATABASES;
  • Choose any table from the DATABASE. To view the tables in the DATABASE use the command SHOW TABLES;

  • Now create the new user and Grant privileges to the new user like CREATE,INSERT,DELETE, e.t.c



  • Login to newly created user: Before login to new user, firstly exit from MySql Command Line Client then after open Command prompt from start -> run -> cmd or command and choose the bin folder