mysql and java: check if user hat right to change database structure

Posted on 2011-09-19
Last Modified: 2012-05-12
hello all,

in a java project i would like to check a database user if he has right of change database structure. (such as drop_priv, alter_priv, delete_priv)

the first question is: how do i check the drop right of  'myuser' , who has localhost as host.
here some details:
in mysql, i have tried to use
select Delete_priv from mysql.user where User='myuser';
to find if use has delete right. but the result i got is "Yes" and "No". because in database there are two users with the same name, one has "localhost" as host, another has "%" as host.  

second question is: how do i get the result of sql above in java code?

Question by:wantime
  • 3
  • 2
LVL 47

Accepted Solution

for_yan earned 167 total points
ID: 36563504
do you mean that you are happy with your sql, you just want to know how to get it in the java code?

If so, then you need to use JDBC

If  your question is different, please, elaborate
LVL 86

Assisted Solution

CEHJ earned 333 total points
ID: 36563822
You probably want the following and you can get the result in java by using this in the usual way, as any other query
select user from mysql.user where user = 'myuser' and host = 'localhost' and drop_priv = 'Y';

Open in new window


Author Comment

ID: 36565674
thanks. the first question is resolved.  i have used

select Delete_priv from mysql.user where User='myuser' and host ='localhost';

to found to priv for user.

yes, i need to get the result in java code. i will have a look at the links you given.
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

LVL 86

Assisted Solution

CEHJ earned 333 total points
ID: 36565795
>>yes, i need to get the result in java code.

That's pretty straightforward. See

Author Comment

ID: 36566772
thanks!  The problem in mysql is resolved. however, i also face the problem in mssql database. so i open a new thread about this issue. the link is here:
LVL 86

Expert Comment

ID: 36567616
thanks. the first question is resolved.  i have used

select Delete_priv from mysql.user where User='myuser' and host ='localhost';

(which was suggested by me, so i don't know why you accepted a different answer wantime..?)

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 38
PHP: concatenate query 13 68
Running JavaFX on JDeveloper 12C 1 32
How do I remove an object from a 3 25
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question