I want to connect my database named aaa via jdbc. I tried using type 1 driver and wrte this quote but the error"[Microsoft][ODBC Driver Manager] Invalid string or buffer length" type 1 code :
import java.sql.*;
import java.io.*;
class test {
public static void main(String a[]) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("first");
Connection con=DriverManager.getConnection("jdbc:odbc:trial","sa","qwerty");
System.out.println("second");
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
Then i tried using type 4 driver and i'm getting a compilation error with the getConnection() method type 4 code:
import java.sql.*;
import java.io.*;
class t {
public static void main(String arg[]) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("first");
Connectin con= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=aaa","sa","qwerty");
System.out.println("second");
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
Please can some one help me out with these two problems