Results 1 to 17 of 17
Thread: failed to connect to DB
- 05-24-2010, 03:41 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
- 05-24-2010, 04:03 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show that what you've done so far?
- 05-24-2010, 04:12 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
here is all i have done
package project_java;
import java.sql.*;
public class thuxem {
public static void main(String args[] ){
Connection con=null;
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc: odbc:db1odbc";
Class.forName(driver);
con = DriverManager.getConnection(url,"root","");
}
catch (ClassNotFoundException e)
{
System.out.println("khong tim thay driver");
}
catch (SQLException e)
{
System.out.println("Khong ket noi duoc voi co so du lieu");
}
}
}
- 05-24-2010, 04:16 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 05-24-2010, 04:24 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
hereeeeeeeeeeeeee :|
java.sql.SQLException: No suitable driver found for jdbc: odbc:db1odbc
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at project_java.thuxem.main(thuxem.java:10)
- 05-24-2010, 04:26 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's all about, your connection is not a valid one.
- 05-24-2010, 04:27 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 05-24-2010, 04:35 PM #8
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
- 05-24-2010, 04:41 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
Forget about my previous reply: I just noticed that you're using the jdbc-odbc bridge and that one comes with your Java distribution; I googled a bit and saw that you have to install it as:
Class.forName( ... ).newInstance(), i.e. you have to instantiate a driver object, not just load the class.
kind regards,
JosLast edited by JosAH; 05-24-2010 at 04:52 PM.
- 05-24-2010, 05:10 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,452
- Rep Power
- 16
You alos appear to have a space in the middle of your connection string:
"jdbc: odbc:db1odbc"
That would get you an no valid driver exception even with the jar file in the classpath.
- 05-24-2010, 05:16 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
Yep, I also noticed that (see reply #7) but this bloody forum software also inserts spaces spontaneously; I think it's the lack of the newInstance() method call; that seems to be the way that bridge wants to be installed. Oh well, we'll wait for the net stack trace ;-)
kind regards,
Jos
edit: forget about that newInstance() too; the fault is that space in your URL.Last edited by JosAH; 05-24-2010 at 05:24 PM.
- 05-24-2010, 05:18 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,452
- Rep Power
- 16
I've seen it in the stacktraces before, but it's also in the code...so I suspect it's real.
- 05-24-2010, 05:19 PM #13
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
like this :
but it show the error that" unhandled exceptiontype"package project_java;
import java.sql.*;
public class thuxem {
public static void main(String args[] ){
Connection con=null;
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:db1odbc";
Class.forName(driver).newInstance();// unhandled exceptiontype
con = DriverManager.getConnection(url,"root","");
}
catch (ClassNotFoundException e)
{
System.out.println("khong tim thay driver");
}
catch (SQLException e)
{
System.out.println("Khong ket noi duoc voi co so du lieu");
e.printStackTrace();
}
}
}
- 05-24-2010, 05:27 PM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 05-24-2010, 05:34 PM #15
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
no no, i make space there because when i type ":"+"o" = :o it's a fun image. so it's not problem :|
- 05-24-2010, 05:35 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,452
- Rep Power
- 16
That's why you should use CODE tags, and not QUOTE tags.
- 05-25-2010, 11:27 AM #17
Member
- Join Date
- Apr 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
JVM creation failed
By RogerP in forum NetBeansReplies: 12Last Post: 10-08-2011, 09:33 PM -
gwt 2.0 hosted mode "plugin failed to connect to hosted mode server"
By turanan in forum New To JavaReplies: 0Last Post: 03-18-2010, 05:39 PM -
my Quicksort attempt has failed
By Jeremy8 in forum New To JavaReplies: 4Last Post: 11-16-2009, 02:56 AM -
Failed in reading xml
By gayathri_g in forum New To JavaReplies: 0Last Post: 08-27-2009, 02:07 PM -
failed to connect to remote vm
By plummer in forum EclipseReplies: 1Last Post: 05-08-2009, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks