Results 1 to 3 of 3

Thread: Sql

  1. #1
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default Sql

    package first;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;

    public class A
    {
    public static void main(String[] args) throws ClassNotFoundException, SQLException
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:oracle-datasource");
    Statement stmt = con.createStatement();
    stmt.execute("create table tab1(sno int, name varchar(60))");
    System.out.println("done");
    }
    }
    output:-
    Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknow n Source)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at first.A.main(A.java:13)

    DataSourceName:-dataSource-orcl
    userName:-system
    password:-mahesh


    i got an Run-time err in the below line
    Connection con = DriverManager.getConnection("jdbc:odbc:oracle-datasource");

    what is the mistake i did in the prog.?
    the data source name,userName & password is mentioned in the above

  2. #2
    Lawl is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    I'm not completely sure of this, but when you establish connection to the database you don't seem to give it a username or password. Try adding that to the end of your connection statement. :) If i remember correctly it should look like this:
    Connection con = DriverManager.getConnection("jdbcdbcracle-datasource", "system", "mahesh");

    PS: I'm a beginner but this is what caught my eye ;) Remember to release connection also ;)

  3. #3
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default

    Quote Originally Posted by Lawl View Post
    I'm not completely sure of this, but when you establish connection to the database you don't seem to give it a username or password. Try adding that to the end of your connection statement. :) If i remember correctly it should look like this:
    Connection con = DriverManager.getConnection("jdbcdbcracle-datasource", "system", "mahesh");

    PS: I'm a beginner but this is what caught my eye ;) Remember to release connection also ;)
    thanks.
    Connection con = DriverManager.getConnection("jdbc:odbc:dataSource-orcl", "system", "mahesh");
    it worked,but i did not release any connection as such.!

    Daya

Posting Permissions

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