Solved

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

Posted on 2011-09-19
6
280 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
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
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
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

0
 

Author Comment

by:wantime
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.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 333 total points
ID: 36565795
>>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
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:

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

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 39
Create a Select Query and Populate a Table 3 45
more than one jdk and one jre 1 34
reverse digits of a number using for loop 5 36
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

867 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

15 Experts available now in Live!

Get 1:1 Help Now