Solved

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

Posted on 2011-09-19
6
279 Views
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?

thanks,
wantime
0
Comment
Question by:wantime
  • 3
  • 2
6 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 167 total points
Comment Utility
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
http://download.oracle.com/javase/tutorial/jdbc/

If  your question is different, please, elaborate
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 333 total points
Comment Utility
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

0
 

Author Comment

by:wantime
Comment Utility
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.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 333 total points
Comment Utility
>>yes, i need to get the result in java code.

That's pretty straightforward. See http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-basic.html
0
 

Author Comment

by:wantime
Comment Utility
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:

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_27317351.html
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>
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..?)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now