This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Unable to connect java with MS SQL server 2005

 
tamilselvam Velusamy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please someone help me to solve this issue

public class DataBase {
public static void main(String args[])
{
String name="English";
String email="english@gmail.com";
String num="23";
String dname="sa";
String pass="123456";

try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//String url = "jdbc:microsoft:sqlserver://localhost:1433"+";databaseName=master";
//String url = "jdbc:sqlserver://localhost:1433"+";databaseName=master";
String url = "jdbc:sqlserver://127.0.0.1:1433"+";databaseName=master";
Connection con = DriverManager.getConnection(url, dname, pass);
PreparedStatement ps=con.prepareStatement("insert into student values(?,?,?)");
ps.setString(1,num);
ps.setString(2,name);
ps.setString(3,email);
boolean flag=false;
flag=ps.execute();
if(flag)
System.out.println("Inserted successfully");
else
System.out.println("Not inserted ");

}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}



}

}






com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBpack.DataBase.main(DataBase.java:19)

 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are running MS SQL Server 2005 on your computer? Then the error message says it isn't listening on port 1433, which I believe is its default port. Most likely that's because you haven't configured it to listen for socket connections; by default it doesn't do that.

If you're not running it on your computer, but it's running on some other computer, then your URL connection string should use that computer's name instead of localhost.
 
tamilselvam Velusamy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i am running ms sql server 2005 in my computer only, kindly tell me, how can i connect SQL server 2005 and java , both running on my PC only..
 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Most likely that's because you haven't configured it to listen for socket connections; by default it doesn't do that.


In other words, you should check the configuration of the database server and change it so that it listens for socket connections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic