Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Tolls

Thread: unable to connect sql server to simple java app through jdbc

  1. #1
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Question unable to connect sql server to simple java app through jdbc

    1.Created this simple program:

    import java.sql.*;
    public class Au{
    public static void main(String args[]){
    try{



    String str="SELECT * FROM authors";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:MyDataS ource");
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery(str);
    System.out.println("Author ID\tFirst Name");
    while(rs.next()){
    String id=rs.getString("au_id");
    String fname=rs.getString("au_fname");
    System.out.println(id+"\t");
    System.out.println(fname);

    }
    con.close();

    }
    catch(Exception ex){
    System.out.println("error occured");
    System.out.println("error:"+ex);
    }

    }

    }


    *it is getting compiled and when i am running it, an exception message is displayed as "java.sql.sqlexception microsoft odbc driver manager invalid string or buffer length" and i also successfully created the database and table but still this exception.... please help

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: unable to connect sql server to simple java app through jdbc

    Use the proper sql server jdbc driver (you'll have to do a search on Microsofts site to find the one for your version), or jtds possibly.
    The JDBC/ODBC bridge is really not a good choice.
    adiotrox likes this.
    Please do not ask for code as refusal often offends.

  3. #3
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: unable to connect sql server to simple java app through jdbc

    I am using 64 bit os(windows 7) can you please suggest me or give me the direct link for my version's supportive sql server jdbc driver....please

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: unable to connect sql server to simple java app through jdbc

    Google it from Microsoft.
    That's what I'd have to do...
    Please do not ask for code as refusal often offends.

  5. #5
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: unable to connect sql server to simple java app through jdbc

    i am getting this Microsoft SQL Server JDBC Driver 3.0, a Type 4 JDBC driver... will this also work for type 1 driver???

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: unable to connect sql server to simple java app through jdbc

    Why do you need a Type 1?
    Please do not ask for code as refusal often offends.

  7. #7
    adiotrox is offline Member
    Join Date
    Feb 2012
    Posts
    43
    Rep Power
    0

    Default Re: unable to connect sql server to simple java app through jdbc

    sql is useless i downloaded that type 4 driver but it's not getting activate.... can you tell me more about java db
    Last edited by adiotrox; 02-25-2012 at 05:27 AM.

Similar Threads

  1. Unable to connect to ftp server java
    By sagngh8 in forum Networking
    Replies: 1
    Last Post: 12-22-2010, 04:55 AM
  2. unable to connect remote database using jdbc
    By enggvijaysingh@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 12-16-2010, 12:16 PM
  3. Replies: 4
    Last Post: 09-07-2010, 06:51 AM
  4. Replies: 4
    Last Post: 02-04-2009, 03:19 PM
  5. I m unable to connect one frame 2 the other
    By ankitraghuvanshi in forum NetBeans
    Replies: 2
    Last Post: 10-23-2008, 02:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •