I am trying to use below code for java to sqlserver connectivity..
import java.sql.*;
import java.util.*;
import java.io.*;
import java.lang.*;
public class AuthorsInfo1
{
public static void main(String args[])
{
try
{
String str = "select * from authors where au_city like 's%'";
String str1 = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(str1);
Connection con = DriverManager.getConnection("jdbc:sqlserver://sqlserver01;databaseName = java;user = sneha;password = sneha_2608");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(str);
System.out.println("Author ID\tAuthor Name\tCity");
while (rs.next())
{
String id = rs.getString("au_id");
String name = rs.getString("au_name");
String city = rs.getString("au_city");
System.out.print(id + "\t");
if (name.length() <= 7)
{
System.out.println(name + "\t\t");
}
else
{
System.out.println("\t" + name + "\t");
}
System.out.println(city);
}
con.close();
}
catch (SQLException e)
{
System.out.println("Error Occured");
System.out.println("Error:" + e);
}
}
}
but it give me this error:
AuthorsInfo1.java:13: unreported exception java.lang.ClassNotFoundException; mus
t be caught or declared to be thrown
Class.forName(str1);
please give me solution for it.....