0

This is my code, I added sqljdbc4.jar, im using sql ms server ..

try
{
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    System.out.println("Loaded");


    Connection connection = DriverManager.getConnection("jdbc:sqlserver:VAIO:1434;databaseName=MyDB");
    System.out.println("started");
    PreparedStatement stmt = connection.prepareStatement("INSERT INTO Tag_Info (TagNo, LastSeenTime) VALUES ('"+ID+"','"+Last+"')");
    stmt.executeUpdate();
    System.out.println("Data Inserted");
    connection.close();
}
catch (Exception e)
{
    e.printStackTrace();
    System.err.println("Problem Connecting!");
}

this is the error message:

java.sql.SQLException: No suitable driver found for jdbc:sqlserver:VAIO:1434;databaseName=MyDB
  at java.sql.DriverManager.getConnection(DriverManager.java:689)
Loaded
  at java.sql.DriverManager.getConnection(DriverManager.java:270)
  at com.alien.enterpriseRFID.examples.AlienClass1ReaderTest.<init>(AlienClass1ReaderTest.java:59)
  at com.alien.enterpriseRFID.examples.AlienClass1ReaderTest.main(AlienClass1ReaderTest.java:91)
Problem Connecting!
tshepang
  • 12,111
  • 21
  • 91
  • 136
  • May depend on the version of Java you are using. http://technet.microsoft.com/en-us/library/ms378422.aspx – smoore4 Apr 28 '14 at 13:31

1 Answers1

0

Use "//" in the connection string:

DriverManager.getConnection("jdbc:sqlserver://VAIO:1434;databaseName=MyDB");

And while it is good practice to change the default SQL Server port, the default is 1433. 1434 is for UDP.

smoore4
  • 4,520
  • 3
  • 36
  • 55
  • thanks for your answer, but I already tried to add "//" it gave me another error says:"The TCP/IP connection to the host VAIO, port 1433 has failed. Error: "Connection refused: connect." – user3581339 Apr 30 '14 at 11:45
  • I see. Try adding user/pw or stop your firewall. Likely one or the other, or both. "jdbc:sqlserver://VAIO:1434;databaseName=MyDB;user=MyUserName;password=*****;" – smoore4 Apr 30 '14 at 12:55