package conn;
import java.sql.*;public class doconnection {
public static Connection getConnection() {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:mydsn";
String username = "rosen";
String password = "1234";

Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, username, password);

} catch(ClassNotFoundException e) {
e.printStackTrace(System.err);

} catch(SQLException e) {
e.printStackTrace(System.err);
}

return con;
}

public static void main(String[] args) {
System.out.println(getConnection());
}
}
当然自带