0

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

0

1 Answer 1

1

In your second example there is a typo: Connectin con=... to Connection con=...!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.