
import java.sql.*;
import java.util.*;
class MyDbCode3*
{
public static void main(String [] args)
{
try `print("code sample");`
{ `print("code sample");`
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnf)
{
System.out.println("Cannot load the Driver");
System.exit(1);
}
Scanner kb=new Scanner(System.in);
int id;
System.out.println("Enter bookid:");
id=kb.nextInt();
try
{
Connection conn=DriverManager.getConnection("jdbc:odbc:advdsn1","student","myself"); Statement st=conn.createStatement();
String qry="Update mybooks set price=price+1000 where bookid="+id; System.out.println(qry); int x=st.executeUpdate(qry); System.out.println("Rows effected="+x);
conn.close();
}
catch(SQLException sq)
{
System.out.println("Sql Error:"+sq.getMessage());
}
}
}
****for running this program i am using jdk1.5.0`*print("code sample");*`
I have created Dsn Successfully ,table also has been created successfully and when i compiled this program then it compiled successfully ,but when i run it ,it gives following error->
C:\Program Files\Java\jdk1.5.0\bin>java MyDbCode3 Enter bookid: 101 Sql Error:[Microsoft][ODBC Driver Manager] Data source name not found and no def ault driver specified
i want to know what is the problem? and how can i run it successfully? please give me a satisfieng answer ,bcz i am not satisfied by ur previous answer...
thank u ....****
View Answers
Post***

1)create database and table 2)write the java code 3)provide ODBC connection 4)execute your code...
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.