wood burning stoves 2.0*
The moose likes JDBC and the fly likes How I know what JDBC driver i to use and where i can get this driver name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How I know what JDBC driver i to use and where i can get this driver name" Watch "How I know what JDBC driver i to use and where i can get this driver name" New topic
Author

How I know what JDBC driver i to use and where i can get this driver name

Anthony Levis
Greenhorn

Joined: Dec 15, 2004
Posts: 10
The source code below is the example code that i download from internet.
but i cannot run it...
when i run it, the result show me

>>Got an exception!
>>com.sybase.jdbc.SybDriver"

so i wish to know how to begin loading the driver and how i know the driver that i need to use.where i can get the driver name like "com.sybase.jdbc.SybDriver". i c many example, the driver name is different.

Help me plz.........
--------------------------------------------------------------------------
import java.sql.*;

class JdbcTest1 {

public static void main (String[] args) {
try {

// Step 1: Load the JDBC driver.
Class.forName("com.sybase.jdbc.SybDriver");

// Step 2: Establish the connection to the database.
String url = "jdbc:msql://www.myserver.com:1114/contact_mgr";
Connection conn = DriverManager.getConnection(url,"","");
System.out.println("AAA") ;

} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

so i wish to know how to begin loading the driver and how i know the driver that i need to use

First step is to get a driver for the Database you are using (tip: type into google "JDBC driver database type"). Then you have to load the driver class - your Class.forName("blah") line. Check the driver docs - thay always include example code to do this.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Anthony Levis
Greenhorn

Joined: Dec 15, 2004
Posts: 10
then can u tell me y this program cannot run in my pc...
y the result no print out AAA.....

it just show me Got an exception!
com.sybase.jdbc.SybDriver

i duno y it put "com.sybase.jdbc.SybDriver"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


i duno y it put "com.sybase.jdbc.SybDriver

"it" didn't put "com.sybase.jdbc.SybDriver", you did. And if you don't understand why, read the documentation which comes with your driver, since that should have an example of how to establish a connection.

A word of advice: posts made in poor quality English tend to get a frosty response here, since it makes things unnecessarily difficult for non-English speakers.
[ December 15, 2004: Message edited by: Paul Sturrock ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How I know what JDBC driver i to use and where i can get this driver name