Wrox Programmer Forums
|
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
 
Old July 16th, 2005, 04:15 AM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default new to jdbc

hello friends

can anybody let me know taht how to insert data in table through jdbc. I have tried for this but it is not working ..

Statement st = dbConnection.executeStatement("INSERT INTO tab (capital) VALUES (2000)");

thanks

HumaMunir
__________________
HumaMunir
 
Old July 26th, 2005, 03:10 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Try this...

Statement stmt = dbConnection.createStatement();
stmt.executeUpdate("INSERT INTO tab (capital) VALUES (2000)");

In case this doesn't work, I am interested in the error message you are receiving. Also, mention the Database you are working with.

eNJay.

 
Old July 28th, 2005, 04:39 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello
thx for the help but its still not working ..
..i have not used any specific database its just for trial, only with student names.
.. i am sure i am doing any silly mistake, well check this out :)

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 (zia)");



         }
        catch(ClassNotFoundException cnfe)
        {
            System.err.println(cnfe);

        }
        catch(SQLException sqle)
        {
            System.err.println(sqle);

        }

    }
}

and here is the exception when i run the program.
 java.sql.SQLEXCEPTION: [MICROSOFT][ODBC MICROSOFT ACCESS DRIVER] Too few parameters. Expected 1.

regards

HumaMunir
 
Old August 1st, 2005, 04:26 PM
Authorized User
 
Join Date: Dec 2004
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





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





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