The Artima Developer Community
Sponsored Link

Java Answers Forum
SQL server connecting problem

1 reply on 1 page. Most recent reply: Jun 9, 2008 6:46 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

SQL server connecting problem Posted: Mar 29, 2008 11:58 PM
Reply to this message Reply
Advertisement
I m using SQL server express edition.I can log in to the server using login name and password by sql server management studio express.But I cant connect to the server using my following java code.I m using jTDS JDBC driver for sql server 2005 express.

import java.sql.*;
import java.sql.Driver;

public class testconn {
Statement stmt;
Connection con = null;
String serverName = "localhost:1433";
String mydatabase = "IDLC-Customer";
//url format- jdbc:jtds:<server_type>://<server>[:<port>][/<database> ]
String url = "jdbc:jtds:sqlserver://" + serverName + "/" + mydatabase; // a JDBC url
String username = "Tanvir";
String password = "abcd";

testconn()
{
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con= DriverManager.getConnection(url, username, password);


if(!con.isClosed())
System.out.println("Successfully connected to " +
"SQL server using TCP/IP...");

} catch(Exception e) {
System.err.println("Exception: " + e); }
/*
finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
} */


}

public static void main(String args[]) {

testconn tc=new testconn();
}
}


cud anybody pls help me?


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: SQL server connecting problem Posted: Jun 9, 2008 6:46 AM
Reply to this message Reply
Badly formatted code. Are you still having this problem?
If so please place Errors/Warnings from any logs/console that you are getting. Please use the java tags when posting code.

Flat View: This topic has 1 reply on 1 page
Topic: how to display the picture when the filename is not in order Previous Topic   Next Topic Topic: Null pointer exception during executeUpdate(sql)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use