Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 16th, 2005, 04:22 AM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old July 29th, 2005, 02:56 AM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #3 (permalink)  
Old July 30th, 2005, 04:20 PM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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
  #4 (permalink)  
Old August 1st, 2005, 04:29 PM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #5 (permalink)  
Old August 9th, 2005, 06:33 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

you use try....catch block for error and try to get more error message.




Gokulan Ethiraj
  #6 (permalink)  
Old December 23rd, 2005, 11:24 AM
Authorized User
 
Join Date: Dec 2005
Location: Bangalore, , India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use PreparedStatement.

That will automatically do the conversions internally.
That's the power of JDBC.

  #7 (permalink)  
Old January 5th, 2006, 06:31 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you could try this:
 ...
String sql="insert into name (students)"+"values('"+Allah+"')";
int result=stmt.Update(sql);
if it success result returns 1.

  #8 (permalink)  
Old January 5th, 2006, 02:46 PM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks :)

HumaMunir
  #9 (permalink)  
Old February 28th, 2006, 03:09 AM
Registered User
 
Join Date: Feb 2006
Location: hyderabad, AP, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
.


  #10 (permalink)  
Old March 1st, 2006, 03:01 AM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDBC 4.0 billfly BOOK: Professional Java, JDK 6 Edition ISBN: 978-0-471-77710-6 2 February 11th, 2007 10:53 AM
JDBC visva4u3 Java Databases 0 April 19th, 2006 06:35 AM
JDBC cooldude87801 BOOK: Beginning Java 2 2 July 30th, 2004 01:08 AM
Cannot load JDBC driver class with com.mysql.jdbc. dzis Apache Tomcat 0 January 29th, 2004 11:57 AM
Cannot load JDBC driver class with com.mysql.jdbc. dzis MySQL 0 January 29th, 2004 11:31 AM



All times are GMT -4. The time now is 11:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.