Results 1 to 7 of 7
- 02-24-2012, 02:42 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 43
- Rep Power
- 0
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
- 02-24-2012, 03:01 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
- 02-24-2012, 03:07 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 43
- Rep Power
- 0
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
- 02-24-2012, 03:14 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 02-24-2012, 03:20 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 43
- Rep Power
- 0
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???
- 02-24-2012, 03:30 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 02-24-2012, 04:22 PM #7
Member
- Join Date
- Feb 2012
- Posts
- 43
- Rep Power
- 0
Similar Threads
-
Unable to connect to ftp server java
By sagngh8 in forum NetworkingReplies: 1Last Post: 12-22-2010, 04:55 AM -
unable to connect remote database using jdbc
By enggvijaysingh@gmail.com in forum Advanced JavaReplies: 1Last Post: 12-16-2010, 12:16 PM -
Netbeans 6.5 unable to connect MS SQL Server 2005 Express
By dpk_vash in forum NetBeansReplies: 4Last Post: 09-07-2010, 06:51 AM -
how to connect a driver in java for jdbc connections to oracle10g
By swathi palla in forum New To JavaReplies: 4Last Post: 02-04-2009, 03:19 PM -
I m unable to connect one frame 2 the other
By ankitraghuvanshi in forum NetBeansReplies: 2Last Post: 10-23-2008, 02:24 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks