Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create SQL server2005 database on remote machine using jdbc?

 
Praveen Kumarji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am creating a desktop application, in which i have to login into sql server 2005 on the remote machine & have to create database, User etc, by using jTDS i am able to create connection to database as well as able to execute "SELECT" commnads but not able to execute database commands like- create database, create user etc.

can any one guide me how do i do this?
Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to execute DDL statements. What happened when you tried? Did you get an error message?
 
Praveen Kumarji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i am getting error
java.sql.SQLException: CREATE DATABASE permission denied in database 'master'.


here is my test code-
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user you connect with does not have permission to create databases. Speak to your SQL Server admin.
 
Praveen Kumarji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I knew that, but my problem is that I have to prepare database on remote machine (which will be having SQL server 2005 installed on it and i have to login into that using window authentication) for the use of my application (creation of user and database) by using JDBC only.

can you please suggest how my user can be added to database as sysadmin role, or any other idea if you have? I think using SQL CMD it is possible but dont know how!!!
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...can you please suggest how my user can be added to database as sysadmin role, or any other idea if you have? I think using SQL CMD it is possible but dont know how...

Your DB admin should create a user/add the privilege to an existing user. You should talk to your SQL server admin as Paul suggested.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don;t need a user in sysadmin role to create databases, the user just needs that specific operation granted to them. You can alter your user via T-SQL (run from Java code if needs be) but my guess is you will probably not have permission to do that either. Speaking to your database admin will speed this process up no end.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic