Jump to content

[JAVA] ODBC Error

- - - - -

  • Please log in to reply
No replies to this topic

#1
jashsayani

jashsayani

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I have written a basic code to open a SQL database and add and update records, but I get the following error:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Here is the code:

import java.sql.*;

import java.util.*;


class database_main {


        public static void main(String args[])

        {

                Connection con;

                Statement stmt;

                String url;

                String sql;

                try {

                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                }

                catch(ClassNotFoundException ce) {

                        System.out.println(ce);

                }

                try{

                        url="jdbc:odbc:test";

                        con=DriverManager.getConnection(url);

                        sql="Delete from friends where rtrim(name) like \'Kim\';";

                        

                        System.out.println("  ");

                           stmt=con.createStatement();

                           stmt.executeUpdate(sql);

                        System.out.println("Record for Kim has been deleted");

                           con.close();

                           con=DriverManager.getConnection(url);

                        sql = "Update friends set city = \'Denver\' where rtrim(name) like \'Melinda';";

                        System.out.println("  ");

                        stmt=con.createStatement();

                        stmt.executeUpdate(sql);

                        System.out.println("Record for Melinda updated.");

                }

                catch(SQLException ce) {

                        System.out.println(ce); 

                }

        }

        

        

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users