Java with Sql Server

How to Connect Java with Sql Server :

1.import sql package

2.Give all the Supporting class in class.forName

3.Give Ipaddress or Computer Name in dburl or in getConnection

4.Use 1433 port Number as Default Port.

5.Give Username and Password in getConnection

6.Open the Connection using createStatement

7.Execute the query String using executeQuery Statement

8.Fetch the Record one by one Using ResultSet

9.Close the Connection

import java.io.*;
import java.sql.*;
public class sqlserverConnection
{
public static String dburl=”jdbc:mysql://localhost:1433”;
public static String username=”admin”;
public static String pwd=”pass”;
public static Connection con=null;
public static Statement stmt=null;
public static ResultSet rs=null;

public static void main(String[] args)
{
try {

Class.forName( “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
con=DriverManager.getConnection(dburl,username,pwd);
stmt=con.createStatement();
rs=stmt.executeQuery(”SELECT * FROM demo”);
while(rs.next())
{
String name=rs.getString(1);
}
}
catch(SQLException sqlExcp)
{
sqlExcp.printStackTrace();
}
}
}

Popularity: 1% [?]

Related posts:

  1. Java with Mysql
  2. JSP Applet tag
  3. Sql Server Interview Questions – Part 1
  4. JSP Custom tags Example
  5. Accessing Private Variable
You can leave a response, or trackback from your own site.

Leave a Reply

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars