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
posted Sep 25, 2005 00:41:00
0
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: 26496
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
subject: problem in enterin data through jdbc:odbc