Deals

Creating New Database Connection in NetBeans for SQL Server

Prerequisites: SQL Server 2008 R2 Express and NetBeans installed in your computer with jdk1.5 or higher. And also you have to download SQL Server 2008 R2 Express JDBC driver and extract all files to "Microsoft SQL Server JDBC Driver 3.0" folder only. (Do not give any other names. It wont recognize).


Once the above prerequisites are completed, create a database and tables in SQL Server of your requirement.


1. Creating database in SQL Server 2008 R2 Express:
  1. Login to Server.
  2.                     
  3. Create Database. (Example : MyDB).
  4. Create table inside MyDB.( Example: EMP).
  5. Save all and execute any query to know that the database is working fine.
2. Create new Database Connection in NetBeans:
  1. Go to Windows->Services. Right click on Databases and then New Connection. 
  2. Check Data Input mode as "Direct URL Entry".
  3. Select driver name "New Driver".
  4. Click on Add.
  5. Select "sqljdbc4.jar" file from "Microsoft SQL Server JDBC Driver 3.0/sqljdbc<version>/enu/" folder.                                                                 
  6. Enter Username/password of server.
  7. The URL should be: jdbc:sqlserver://localhost:1433/databaseName=<your DB name>; 
  8. Select the schema of your database.
3. Other Settings:
  1. Make sure the Sql server service and Sql Browser service are running. Go to SQL Configuration Manager and click on SQL Server Services and check the services running. If not start them. By default SQL browser service is disabled. you have to enable/set automatic start and run the service.
  1.   One very important setting here is enabling TCP/IP port and setting its IP to 1433. Go to SQL Server Configuration Manager --> SQL Server Network Configuration-->protocols for SQLEXPRESS. Here make sure TCP/IP is enabled. Double click on TCP/IP and then on IPAdresses and go to IP All and set TCP Port to 1433.



Now you are all set for developing a database application in NetBeans. Congratulations!!!




1 comment:

Unknown said...

Thanks. This post helped me.

Post a Comment