 |
| Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 16th, 2005, 04:22 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
new to jdbc
hello friends
can anybody let me know that how to insert the data into the table.I have tried for this but it is not working...
Statement st = dbConnection.executeStatement("INSERT INTO tab1 (capital) VALUES (2000)");
thanks
HumaMunir
__________________
HumaMunir
|
|

July 29th, 2005, 02:56 AM
|
|
Authorized User
|
|
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is your column type? Is it a number or is it string type? If it is string tupe you have to wrap the value with ''. Example '2000'
John Dirk
Programming Consulant
http://www.programminghelp4u.com - Programming (Assignment/Project) Help
|
|

July 30th, 2005, 04:20 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thx for the idea but its still not working. the program runs well but it does not show any change in database.
here is my program plz check it out and tell me what mistake i am doing here.
import java.sql.*;
public class Accounts
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String source = "jdbc:odbc:database";
Connection dbConnection = DriverManager.getConnection(source);
Statement stmt = dbConnection.createStatement();
stmt.executeUpdate("INSERT INTO name (students) VALUES ('Abdul Allah')");
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle)
{
System.err.println(sqle);
}
}
}
regards
HumaMunir
|
|

August 1st, 2005, 04:29 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello friends
i have found that the string for update the database in my program should be written in inverted commas i.e
stmt.executeUpdate("INSERT INTO name " + "VALUES ('1','Abdul Allah')");
may be that was the problem with my program bc now it is running without any error or exception but still there is no change in database and no item is added.
i donot know why please help me in this matter
thanking in advance
regards
HumaMunir
HumaMunir
|
|

August 9th, 2005, 06:33 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
|
|
you use try....catch block for error and try to get more error message.
Gokulan Ethiraj
|
|

December 23rd, 2005, 11:24 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Use PreparedStatement.
That will automatically do the conversions internally.
That's the power of JDBC.
|
|

January 5th, 2006, 06:31 AM
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
you could try this:
...
String sql="insert into name (students)"+"values('"+Allah+"')";
int result=stmt.Update(sql);
if it success result returns 1.
|
|

January 5th, 2006, 02:46 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks :)
HumaMunir
|
|

February 28th, 2006, 03:09 AM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello ,
try this
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:userDSN name","scott","tiger");
Statement st=con.createStatement();
Here Dsn name: go to CONTROL Panel and open ADMINISTRATIVE TOOLS
and then open DATA SOURCE(ODBC).
it opens a window,in that 7 tabs are there.
chose userDSN(Default it open).
and PRESS the ADD button.it shows the some default and inistalled Database choose (ORACLE database)then click Finish.
and it asks the name(dsn )then ok.
int n=st.ececuteUpdate("insert into tabs"+"values('"+name+"')");
do this
.
|
|

March 1st, 2006, 03:01 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for giving me such a great detailed reply. well the problem has solved already but i must oblige for your help.
Thanks once again
Take care
HumaMunir
|
|
 |