Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in enterin data through jdbc:odbc

 
mayank yadav
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ....
it really worked...
please advice me how to procede
further in passing values from an applet
to this application..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The applet part of this question is being discussed in the Applets forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic