Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new to JDBC. Please help !

 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is wrong with the code . I,am using MS Access as the database. I've created a System DSN (mydsn).When i select the records its gives me a fine result but at the time of insertion nothing happens . The variable rows return 1 but no rows are updated .
I also tried to insert the values throught a prepared statement .

Please guide me a bit
Thanks in advance
[ April 29, 2003: Message edited by: raghav mathur ]
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help . This is really urgent .
Thanks in advance
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raghav,
In the code you have posted, as far as I can tell, you are not closing any of your JDBC-related objects -- like "Statement" and "Connection". Are you performing the "close()" method for your "Statement" object?
Also, how do you know that the database is not getting updated? Perhaps you are incorrectly trying to verify the update? How, exactly are you checking this?
Apart from the "close()" that I mentioned above, the rest of your code looks fine to me -- plus the fact that you claim that the "executeUpdate()" method (in your code) is returning 1. This indicates that the "insert" is being performed.
Hope this helps.
Good Luck,
Avi.
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Avi Abrami:
Hi Raghav,
In the code you have posted, as far as I can tell, you are not closing any of your JDBC-related objects -- like "Statement" and "Connection". Are you performing the "close()" method for your "Statement" object?
Also, how do you know that the database is not getting updated? Perhaps you are incorrectly trying to verify the update? How, exactly are you checking this?
Apart from the "close()" that I mentioned above, the rest of your code looks fine to me -- plus the fact that you claim that the "executeUpdate()" method (in your code) is returning 1. This indicates that the "insert" is being performed.
Hope this helps.
Good Luck,
Avi.

HI
1)Yes the row returns 1 . I,am sure of that .
2)I,am not closing the statment object .
3) After performing the insert statement i browse through the records in the databese and can't the record which i recently inserted.
Anything else do i need to do ?
Thanks in advance
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avi
It worked .... i was not closing the objects which i had opened.
Thanks a ton . God bless you !
One more thing .
How do i connect to a My Sql database ?
[ April 30, 2003: Message edited by: raghav mathur ]
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raghav mathur:
Hi Avi
How do i connect to a My Sql database ?
[ April 30, 2003: Message edited by: raghav mathur ]

Class.forName("org.gjt.mm.mysql.Driver");//older driver
Class.forName("com.mysql.jdbc.Driver");//for new driver
connection=DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","<user>","<password>");
use the "Class.forName" string according to the driver you have downloaded...
HTH
MB
[ May 01, 2003: Message edited by: Malhar Barai ]
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Malhar Barai:

Class.forName("org.gjt.mm.mysql.Driver");//older driver
Class.forName("com.mysql.jdbc.Driver");//for new driver
connection=DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","<user>","<password>");

Thanks .
What if my database resides on www.abc.com . In that case how will i connect from the client which resides on local machine.
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raghav mathur:

Thanks .
What if my database resides on www.abc.com . In that case how will i connect from the client which resides on local machine.

replace "localhost" with the IP address of the remote server where the database resides..
HTH
MB
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a TON !!!
please if you also solve another query of mine .
http://www.coderanch.com/t/335690/GUI/java/refreshing-screen

Thanks in advance
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
One last things guys .
I need to connect to the My Sql database . I need to create a DSN on the fly . HOw do i do that ??
Please reply as soon as possible
Thanks a ton in advance
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
I could find the syantax for conecting on the fly DSn for MySql . Suppose i do not have the driver to connect to it( right now i,am connecting to a local database where the drivers are loaded)
Then how can such a thing be achieved ???
Please reply as soon as possible
Thanks a ton in advance
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
i,am trying to run the following programm.

i 've created this on the fly dsn . Now if i specify anything else except the "localhost" . it doesn't connect .i may need to connect to some other ip then what should i do in that case ???
Please help me !
[ May 07, 2003: Message edited by: raghav mathur ]
 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
It works . I was specifying the wrong driver .
1 more prob
http://www.coderanch.com/t/298661/JDBC/java/stange-MySql-driver
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic