aspose file tools*
The moose likes JDBC and the fly likes problem in enterin data through jdbc:odbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in enterin data through jdbc:odbc" Watch "problem in enterin data through jdbc:odbc" New topic
Author

problem in enterin data through jdbc:odbc

mayank yadav
Greenhorn

Joined: Sep 25, 2005
Posts: 11
i have just started with JDBC
i tried a simple program for viewing and entring
values in MS Access.....in the below code i can retrieve
the values but cannot enter .....plzzz help




import java.sql.*;
import java.awt.*;


class Net2
{

public static void main(String ar[])


{
try {

// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Step 2: Establish the connection to the database.
String url = "jdbc dbc:mayank";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();
ResultSet rs ;


//these two statements does not execute durin the program

//int m;


//st.executeUpdate("insert into mayank values('NITS') ");



rs = st.executeQuery("select class from mayank ");

conn.commit();

while(rs.next())
{
//System.out.println("ass");
System.out.println(rs.getString("class"));
//System.out.println("ass");

}


}

catch (Exception e)

{
e.printStackTrace();
/*System.err.println("Got an exception! ");
System.err.println(e.getMessage());
*/
}
}
}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

There is a problem wit hteh Type 1 Driver which causes it to 'cache' quesries and not pass them to the database. You can search this forum for other solutions, but one fix is here.
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Mayank,

Known Access issues aside there are two major problems with the code you posted. The first is a SQL issue. When you have the following query


that assumes that the table mayank only has one column/field. If it has more than one then this query will not work.

based on how you do the SELECT later on I think your insert query should be



The second problem in your code is even more severe. The line where you are executing your update (in this case INSERT SQL) has been commented out.
mayank yadav
Greenhorn

Joined: Sep 25, 2005
Posts: 11
thanks ....
it really worked...
please advice me how to procede
further in passing values from an applet
to this application..
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

The applet part of this question is being discussed in the Applets forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in enterin data through jdbc:odbc
 
Similar Threads
problem in entering values
uanble to wstavlish connection using JDBC and applet
problem in entering values
how to use prepared statement in the given code
linking JDBC with Applet