aspose file tools*
The moose likes JDBC and the fly likes new to JDBC. Please help ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "new to JDBC. Please help !" Watch "new to JDBC. Please help !" New topic
Author

new to JDBC. Please help !

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641

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.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Please help . This is really urgent .
Thanks in advance
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

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

Joined: Jan 12, 2001
Posts: 641
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

Joined: Jan 12, 2001
Posts: 641
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

Joined: Aug 17, 2001
Posts: 399
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 ]

Malhar Barai
SOA & Java Book
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
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

Joined: Aug 17, 2001
Posts: 399
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

Joined: Jan 12, 2001
Posts: 641
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

Joined: Jan 12, 2001
Posts: 641
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

Joined: Jan 12, 2001
Posts: 641
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

Joined: Jan 12, 2001
Posts: 641
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

Joined: Jan 12, 2001
Posts: 641
HI
It works . I was specifying the wrong driver .
1 more prob
http://www.coderanch.com/t/298661/JDBC/java/stange-MySql-driver
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to JDBC. Please help !