How to connect java project to sql server 2008 r2 database

i want to create an java application which has to create a database and later access it. My problem is that i am not able to connect sql server 2008 r2 database driver on to the netbeans.i have sql server 2008 r2 installed on my system.please
suggest me the step by step procedure to establish the connection

Hi ENG,
To establish a connection to SQL Server from a Java project, you have to download the JDBC driver for SQL Server from
here.
After extracting the jar files(like sqljdbc.jar) from the above link, add the driver to the netbeansIDE.
Test establishing a connection with the below Java Class.
import java.sql.*;
public class Test {
public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //load the jdbc driver
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=test"; //connection string to the db hosted on localhost
String userName = "sa"; //user name
String userPwd = "123456"; //password
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //print Connection Successful! if connection establishes
} catch (Exception e) {
e.printStackTrace();
A demonstration video from Youtube for you reference.
Connect NetBeans Project with Microsoft SQL Server 2008 - YouTube
Since this is a question regarding Java, I suggest you post your subsequent questions to a java dedicated forum. It is appropriate and more experts will assist you.
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support

Similar Messages

  • How to connect Java and Microsoft SQL Server 2000

    hi,
    could anyone please teach me how to connect Java and SQL Sever 2000?? if possible could you guys provide me with an example??? i could hardly find any relevant resources about it...
    Thanks ~!

    thanks for the information...
    by the way hv any working module on it?? i'm new to
    both Java and Microsoft SQL Server... Thanks againFirst things first... you should read this:
    http://java.sun.com/docs/books/tutorial/jdbc/
    This is microsofts official JDBC Driver: http://www.microsoft.com/sql/downloads/jdbcregister.asp
    Install it and the documentation has some usage examples

  • How to store jpeg images in SQL server using NI database Connectivity Toolset. Can anyone please help me in this regard.

    Please tell how to store jpeg images in SQL Server using NI Database Connectivity Toolset.

    http://www.w3schools.com/sql/sql_datatypes.asp
    You setup a field as BLOB and store the binary of the picture there. Depending on the database it can be called differently as you can see in the link, in SQL server there's even a Image datatype.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How to connect from InformixDB to SQL Server 2012 (and copy data)

    Hello guys
    I try to build a connection from an Informix (Informix2000) database to my SQL Server 2012.
    I really dont know how to do this...
    The plan is to build a job in the night in which data is beeing copied from the InformixDB to my SQL Server 2012
    The SQL server should be like a "archive server" (same data as informix DB , but the data should stay for 2 years)
    Any idea if this is possible ? (what im trying to do)
    Can i do this with ODBC Connection ?
    Thanks a  lot and Regards, Dominic

    Thanks a lot guys... but what im trying to do is not to migrate the hole Informix DB to SQL 2012, i just want to copy some data into my SQL Server (archive). in the informix DB the data is only 30days back... i want to transfer  every week
    the data and let it on the SQL Server 2 years back. (SQL Server should be like an archive system)
    Hello ,
    Then you need to create an SSIS package to migrate data from Informix to SQL Server 2008 since Informix is old I dont know which connection provider to use but you can try ADO.NET connection provider
    Can you check below link
    http://davidbridge.wordpress.com/2012/05/30/extraction-from-informix-database-using-ssis-data-warehouse-etl/
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • How to connect musicdb to Microsoft SQL Server

    hi..
    i have tried musicdb example with mysql, but i need to connect it to SQL Server.
    i have created a similar DB in SQL SERVER, however i am not able to create a user, similar to musicdbuser and musicdbpass in SQL SERVER.
    Also in the Administrator console i followed these steps.
    1. Applications->web Applications->deployed the war file-> OK
    2.Resources->JDBC->Connection Pool->New->Name ='musicdb-jdbc-pool-SQLserver'->Resource Type='javax.sql.Datasource'->Database Vendor='Microsoft SQL SERVER'-> Next
    added properties Values
    databaseName musicdb(this is the database i created in MS SQL SERVER)
    databaseSourceName musicdb(this is the DSN name i created in control panel->ODBC connections)
    networkProtocol TCP
    user sa (this is the username that i use to start SQL SERVER)
    password syntel123$ (this is the password that i use with the above user )
    portNumber 1443
    serverName localhost
    then i click finish.
    if i say ping to this connection , i get success!!
    3. then i goto resources->jdbc->jdbc resources->new->JNDI Name="jdbc/musicdb"->pool name="musicdb-jdbc-pool-SQLserver'"->ok
    4. Then i click resources->connectors->connector connection pool->new->Name="mep/musicdb"->resource adapter="ds-jcr-connector-jaxrs"->next->finish
    5 Then i click resources->connector resources->new->JNDI name="mep/musicdb"->pool="mep/musicdb"->ok
    however when i hit the URL http://localhost:8080/musicdb/resources/albums
    i get the following error
    type : Exception report
    message
    description: The server encountered an internal error () that prevented it from fulfilling this request.
    exception: javax.servlet.ServletException: com.sun.jersey.api.container.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class com.sun.mep.ws.vtms.util.ConnectionPool
    root cause: com.sun.jersey.api.container.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class com.sun.mep.ws.vtms.util.ConnectionPool
    root cause: java.lang.NoClassDefFoundError: Could not initialize class com.sun.mep.ws.vtms.util.ConnectionPool

    Hi,
    I was able to create a JDBC connection pool for SQL Server successfully and will share the key steps, and was able to create a MEP user with an ECBO connection configured for the SQL Server; However, it looks like there is a "false positive" problem. Even though the user was created with the SQL Server connector whose associated JDBC connection pool passed the Ping test, doing a sync as that user changed the MySQL database album table and not the SQL Sever album table. MEP didn't give any error at all. I will bring this up with our engineers.
    Here are the steps for at least getting GF JDBC connections with SQL Server working.
    1. With MS SQL Sever 2005 Server Management Studio,
    created a 'musicdb' database, a 'musicdbuser' user with password 'musicdbpass',
    and added the 'album' table with
    name (varchar(30) primary key, not null)
    artist (varchar(30), not null)
    date_published (datetime, not null)
    rating (int, not null)
    username (varchar(30), not null)
    2. With MS SQLServer Configuration Manager, enable TCP/IP on static IP address
    and 127.0.0.1 on port 1433 and restarted the SQL Server service
    3. Downloaded Microsoft's 2.0 Driver for SQL Server 2005
    4. Copied the driver sqljdbc4.jar to GF_HOME/domains/mep/lib/ext
    5. Restarted GF
    6. Login to GF Admin Console
    7. Create Resources -> JDBC -> Connection Pool
    name: musicdb_pool_sqlserver
    resource type: javax.sql.DataSource
    datasource class: com.microsoft.sqlserver.jdbc.SQLServerDataSource
    8. Create Resources -> JDBC -> Resource
    name jdbc/musicdb_sqlserver
    9. Go back to musicdb_pool_sqlserver and click Additional Properties then add
    user: musicdbuser
    password: musicdbpass
    serverName=localhost
    portNumber=1433
    databaseName=musicdb
    10. Click General tab and click Ping. Get Success!

  • How to connect to remote MS SQL Server?

    I use:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:iweb",userid,passwd);
    to connect to my "iweb" database on MS SQL Server running locally. Works great.
    But now I want to connect to this same database that is now running on a remote MS SQL Server
    on port 1433 of a machine with IP address 123.456.789.123.
    What is the magic incantation to make this happen? I have been trying variations of:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String conString = "jdbc:odbc:DRIVER={SQL Server};SERVER=123.456.789.123:1433;"
    + "DATABASE=iweb;UID=" userid ";PWD=" passwd ";";
    Connection con = DriverManager.getConnection(conString);
    but no joy. Any help would be greatly appreciated. Surely this is a common problem
    but I'm having a heck of a time finding helpful docs that spell it out.
    -Dave Maffitt [email protected]

    Configuring a local DSN to point to the remote server is a good solution, but, I am still puzzled by something. On page 216 of Core Java 2, Volume 2, Advanced Features, there is an example of a database URL using a network address as part of the value. The example reads in part:
    For example: jdbc:odbc://whitehouse.gov:5000/CATS;PWD=Hillary
    would connect to the CATS database on port 5000 of whitehouse.gov using ODBC attribute value of PWD set to "Hillary".
    This example is what lead me to believe that I might be able to connect to a remote Data Source if I had the right syntax in the URL. My attempts at duplicating this example with my own MS SQL Server 7.0 database are failing. Have you tried this with any success?

  • How to attach .mdf file to sql server 2008 EXPRESS

    I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
    to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
    Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
    Any help??

    I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
    to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
    Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
    Any help??
    You are trying to attach SQL Server 2012  database files to SQL Server 2008 R2 which is not allowed, you either need to upgrade your SQL Server 2008 to 2012 or alternatively you can generate all scripts from SQL Server 2012 and execute it in SQL Server
    2008 R2.
    You can refer below link to how to generate script.
    http://blog.sqlauthority.com/2012/07/18/sql-server-generate-script-for-schema-and-data-sql-in-sixty-seconds-021-video/
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    Praveen Dsa | MCITP - Database Administrator 2008 |
    My Blog | My Page

  • How to store Invalid Dates in SQL Server 2008

    Hi,
    I have SQL Server 2008 and My table has start_Date and end_date column which is DATETIME datatype.
    Somehow my table is having invalid dates which is lesser than 1753-01-01 00:00:00.0 range.
    I want to know how this date get inserted in the SQL Server. 
    Thanks,
    Muthuprabhu

    Can you post the DDL for that table together with a SELECT query and results demonstrating invalid data?
    DECLARE @dt DATETIME = '1753-01-01 00:00:00.0';
    -- Command(s) completed successfully.
    DECLARE @dt DATETIME = '1752-01-01 00:00:00.0';
    Msg 242, Level 16, State 3, Line 4
    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
    Datetime conversion:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Connecting apex with micrsoft sql server 2008

    Please help me in connecting database of sql server 2008 data via apex
    prashant

    Maybe this link could help:
    http://www.dbasupport.com/oracle/ora10g/connection01.shtml
    I extended it once for a MySQL connection:
    http://www.apex-at-work.com/2010/02/making-connection-from-oracle-xe-to.html
    Best regards,
    Tobias
    http://www.apex-at-work.com

  • How to configure USER CAL on SQL server 2008

    how to configure or Add User CAL on SQL server 2008?
    pls let me know the process

    Hello,
    There is no CAL management in SQL Server, you have the licenses only "on paper".
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • How to delete the Folder from sql server 2008

    Hi all,
    I was trying to delete the folder from sql server 2008 with the below script
    DECLARE @path VARCHAR(256) -- path for backup files
    DECLARE @cmd VARCHAR(8000)
    DECLARE @folderName VARCHAR(256) -- filename for backup
    SET @folderName = + (CONVERT(varchar(10), GETDATE()-7, 112))  -- 7 days back date folder name
    SET @path = 'I:\Backup_Test\' + @folderName -- Folder path
    SET @cmd = 'del ' + @path -- Delete
    EXEC master..xp_cmdshell @cmd
    --Print @cmd
    This is not working it was asking the Confirmation (I:\Backup_Test\20100629\*, Are you sure (Y/N)? ) what will i do to the delete the folder.
    Thanks,
    Prasad R.

    I would notice   you that T-SQL does not play well to do things like that. Do not you want using .net language to delete folders?
    Old method is
    declare @HR int, @CFOLDER varchar(255),@FSO int
        set @CFOLDER='D:\folder\'
        EXEC @HR = sp_OACreate 'Scripting.FileSystemObject', @FSO OUT
        EXEC @HR = sp_OAMethod @FSO, null, 'DeleteFolder', @CFOLDER 
    Now regarding to your second question please examine xp_fileexist  system stored procedure
    CREATE FUNCTION dbo.fn_file_exists(@filename VARCHAR(300))
      RETURNS INT
    AS
    BEGIN
      DECLARE @file_exists AS INT
      EXEC master..xp_fileexist @filename, @file_exists OUTPUT
      RETURN @file_exists
    END
    GO
    -- test
    SELECT dbo.fn_file_exists('c:\a.txt')
    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/

  • Sharepoint 2013 SSRS Interaction with Sql Server 2012 Reporting Services connecting to Sql Server 2008 R2 database

    Hi
    I'm working on upgrading sharepoint 2010 to sharepoint 2013 with sql server 2008 r2. I've ran into some problems but have been able to get a test farm upgraded. However to run SSRS 2013 it seems Sql Server 2012 Reporting Services are required. Upgrading
    to a full sql server 2012 database isn't an option. I know that sql server 2012 reporting services can use sql server 2008 r2 as a catalog and content database so I was wondering could this be a workaround? Importantly would I need a separate machine/virtual
    machine to host sql server 2012 reporting services? or could it live on the sql server 2008 r2 machine? Any pointers appreciated. Thanks Dan

    Remember that SSRS must be deployed on the SharePoint server. Having said that, yes you can install SSRS 2012 SP1 on a server running SQL 2008 R2. And yes, you can use 2008 R2 as your Database Engine server while SSRS 2012 SP1 runs on the SharePoint server.
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • How to Migrate Stored procedure on Sql server 2008 to Oracle Database

    Guys, I need help vey badly as I am new in this field.
    Problem is that, I have to migrate stored procedure on Sql server 2008 to oracle Oracle database:
    Whole scenario--
    1. Sql Server 2008 application on Windows server (source machine)
    2. I have to migrate 70 Stored Procedure
    3. To Oracle Database on Linux machine (Target machine)
    Any method (no problem)
    Please, help me or give me any reference as I don't know which keyword is differ in both database.
    Thanks in advance

    Hi,
      You could the free Oracle SQL*Developer to do this.
    There is information and a download link here -
    Oracle SQL Developer</title><meta name="Title" content="Oracle SQL Developer"><meta n…
    and information on using it for migrations here -
    http://www.oracle.com/technetwork/database/migration/index-084442.html
    You could use it in 2 ways -
    1. Go through a migration but just pull the stored procedure code from the file created after you generate the SQL from the SQL*Server database
    2. Use the scratch editor accessed from -
    - Tools - Migration - Scratch Editor
    and paste the SQL*Server stored procedure code into the window and it will convert it to Oracle code. The tool is very good but may have problems if you have very complicated procedures that use SQL*Server specific utilities.
    Regards,
    Mike

  • SQL Server 2008 & 2012 Database backup on a shared loaction

    Hi,
    I have to plan for the Database backup on SQL Server 2008 & 2012 on a shared Path.
    We are building a new Maintenance plan &  specify the Database which needs to be backup & at the Folder location we specify the Shared Path Location. These steps I have followed using the below link,
    http://social.msdn.microsoft.com/Forums/en-US/be138ca3-4b2f-4464-8115-9a0a6f2e0fe6/sql-database-backup-on-network-share-using-maintenance-plan?forum=sqldatabasemirroring
    But the operation fails & throws the below error:
    Message
    Executed as user Microsoft (R) SQL Server Execute Package Utility  Version 10.50.1600.1 for 64-bit  Copyright (C) Microsoft Corporation 2010. All rights reserved.    Started:  12:27:17 PM  Progress: 2014-02-13 12:27:19.13    
    Source: {B6CEBA00-4BD1-4931-AF23-B633BEDBEE4A}      Executing query "DECLARE @Guid UNIQUEIDENTIFIER      EXECUTE msdb..sp...".: 100% complete  End Progress  Error: 2014-02-13 12:27:20.63    
    Code: 0xC002F210     Source: Back Up Database Task Execute SQL Task     Description: Executing the query "BACKUP DATABASE DB TO  DISK ..." failed with the following error: "Cannot open backup device
    '\\DBBackup\SharePoint_backup\DB_backup_2014_02_13_122719_5314660.bak'. Operating system error 5(Access is denied.).  BACKUP DATABASE is terminating abnormally.". Possible failure reasons: Problems with the query, "ResultSet" property not
    set correctly, parameters not set correctly, or connection not established correctly.  End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  12:27:17 PM  Finished: 12:27:20 PM  Elapsed:  2.843 seconds. 
    The package execution failed.  The step failed.
    Note: But when I open the shared path in the Windows Explorer it opens successfully.
    Regards,
    Purvish Shah

    Hello,
    >>'\\DBBackup\SharePoint_backup\DB_backup_2014_02_13_122719_5314660.bak'. Operating system error 5(Access is denied.). 
    This clearly points out to fact that your SQL Server service account does not have permission of read/write on shared location,simple.
    >>But when I open the shared path in the Windows Explorer it opens successfully.
    This is because when you are browsing through explorer your windows login credential is used to access that folder but when you are running backup your SQL Server service account permission is used to write backup on shared folder ( which I assume it does
    not have ) so the access denied error.
    Hope this helps
    PS: I reffered the link its maily how you specify backup path its not about access denied error due to SQL server service acount not having privilege
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • SQL Server 2008 R2-Database Curruption

    Dear Sir,
    I have a licensed SQL Server 2008 R2 and i found that my database get corrupted and showing error-message.
    Request you to please give me solution for this error.
    error,
    "Msg 211, Level 23, State 3, Line 1
    Possible schema corruption. Run DBCC CHECKCATALOG.
    Msg 0, Level 20, State 0, Line 0
    A severe error occurred on the current command.  The results, if any, should be discarded."
    Regards
    Keshav

    It looks like that some table in your database has got corrupted.
    Run:
    DBCC CHECKCATALOG
    DBCC CHECKDB (Databasename) with no_infomsgs,all_errormsgs
    Check if it returns any consistency errors!!
    If DBCC checkdb is unable to repair then use backups.
    Have any recent changes made to any table in terms of schema change, data type modification etc..?
    Do you have valid database backup file with you before this issue occurred? If yes, then restore the database using that backup file.
    If not, then create a new database and try importing as much data as possible or if you can identify the culprit table, probably you try dropping & recreating that particular table. 
    Refer:
    http://www.sqlskills.com/blogs/paul/teched-demo-corruptions-fatal-to-dbcc-checkdb/
    http://data-base-recovery.blogspot.in/2012/08/how-to-fix-possible-schema-corruption.html

Maybe you are looking for

  • Problem in F.05 in foreign currency valuation

    Hi all we are facing some problem in the F.05..that is we are getting some amount  difference in one company code 6000 but we do not have any issues with the forex revaluation. We are following the same process for both the company codes i. e 4000 an

  • Error while provisioning to OID group

    Hi, we created 2 groups in OID. we ran OID group lookup Reconciliation task and now we are able to see the created Groups in Lookup.OID.Group. we added the Groups in access policy. but when we are Provisioning Users into OID the Add User to Group tas

  • Creation of Smart Forms for PDF

    Hi All, I am new to SFP. So, please tell me how to create Smart Forms for PDF. I already have an SAP standard form of Customer Invoice in this format (SFP) and I need to change the layout and add some additional fields in it as well. Please guide me

  • Video much too dark in FCP compared to iMovie

    NB I mistakenly asked this question in the Final Cut Pro X forum and should really have posted it here Bit of a newcomer to this but as I have Final Cut Pro 7 thought I'd use it rather than iMovie which seems a bit primitive. Shot a video of someone

  • Error "getDRMAdditionalHeader failed." of PHDS in AMS5.0.5

    Hi, I am trying to update AMS version from 5.0.3 to 5.0.5. But I could not get manifest file(f4m) of PHDS VoD for "Internal Server Error." Please Help me to PHDS config for AMS 5.0.5. Host OS :  CentOS 5.8 and 6.3 64bit. Reproducibility: install # ta