Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please help me in my program which tries to send data to Data base

 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends

please help me in my program which tries to send data to Data base

friends i have created my data base in Microsoft Access Table name is Login

when ihave send data to data base through my program it behaves in unpredictable manner some of the time it takes data in table while some of the time it does not giving Exception but not putting data in table
my Source code is


package exam.Model;

import java.sql.*;
import java.io.*;

public class Database_c {
Connection con;
Statement stm;

public Database_c() throws ClassNotFoundException, SQLException {
/*1 loading driver
The driver is the piece of software that knows how to
talk to the actual database
server
*/
System.out.println("i amin constructer");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("i amin jdbc connection");
/*2 estabishing connection*/

con = DriverManager.getConnection("jdbc dbc:GANESH");

/*3 creating Statement
A Statement object is used to send queries and commands to the database
and is created from the Connection as follows:
*/
stm = con.createStatement();
System.out.println("Statement object created");
}

public void updateTable(String fn, String ln, String ui, String pw) {
/* INSERT INTO table_name
VALUES (value1, value2,....)
*/
System.out.println("i amin update");

try {

stm.executeUpdate("INSERT INTO Login " +
"VALUES ( 'Jay', 'Mr.', 'Viru','sholay')");
/* stm.executeUpdate("INSERT INTO Login" +
"VALUES('pakistan','bangladesh','china','lanka')");*/

}
catch (SQLException e) {
System.out.println("i amin update catch end");
System.out.println("fail to process Query");
}
}

public void checking_member(String ui, String pw) {
String query = "SELECT FROM Login where userid = " + ui +
"ORDER BY password";
try {
ResultSet rs = stm.executeQuery(query);
while (rs.next()) {
String paw = rs.getString("password");
System.out.println(paw);
}

}
catch (SQLException e) {
System.out.println("fail to process Query");
}
}

public static void main(String a[]) throws Exception {
Database_c dc = new Database_c();
dc.updateTable("suchit", "Tatkare", "s.tat", "sus");

}
}


o/p of program is
i amin constructer
i amin jdbc connection
Statement object created
i amin update
hence it does not throw Exception but does not update my data base
what should i do to run this test code correctly
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Had only a quick look, but arent you missing a few close() calls!, on ResultSet, Statement and Connection objects.

Also, you can try calling commit() on the Connection.

HTH
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS Sonny
now it works fine
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic