Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics 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 November 24th, 2007, 01:09 AM
ruzdi
Guest
 
Posts: n/a
Default java-access problems

i have got some problem on accessing Access Database using java

code is given below --

public class insertIntoDatabase{
    private Connection connection,connection2;
    private SqlConnection sqlc,sqlc2;
    private String query;
    public insertIntoDatabase() {
       this.addToDatabase();
    }
    private void add(String query){
        try{
            sqlc = new SqlConnection();
            connection = sqlc.connectionString();
            Statement statement = connection.createStatement();
            statement.executeQuery(query);
            statement.close();
        }catch(SQLException sqlex){
            sqlex.printStackTrace();
            javax.swing.JOptionPane.showMessageDialog(null,"Fa il Message ::"+sqlex.getMessage());
    }
    }
    private void addToDatabase(){
            query = "INSERT INTO names(Title,FName,MName,LName,NName,Suffix," +
                "DBirth,IName) values('"+setValues.strTitle+"','"+setValues.strFN ame+"','"+
                setValues.strMName+"','"+setValues.strLName +"','"+setValues.strNName+"','"+
                setValues.strSuffix+"','"+setValues.strBDate+"','" +setValues.strIName+"')";

            javax.swing.JOptionPane.showMessageDialog(null,"in sert query : "+query);
            add(query);
            query = "INSERT INTO address(AType,Street,Thana,Post,City,State," +
                "Zip,Country) values('"+setValues.strAType+"','"+setValues.strSt reet+"','"+
                setValues.strThana+"','"+setValues.strPost+"','"+s etValues.strCity+"','"+
                setValues.strState+"','"+setValues.strZip+"','"+se tValues.strCountry+"')";

            javax.swing.JOptionPane.showMessageDialog(null,"Ad dress Table : "+query);
            add(query);
            query = "INSERT INTO contacts(CType,ACode,PNumber,MNumber,FNumber,EMail )values('"+
                setValues.strCType+"','"+setValues.strACode+"','"+ setValues.strPNumber+"','"+
                setValues.strMNumber +"','"+setValues.strFNumber+"','"+setValues.strEMa il+"')";

            javax.swing.JOptionPane.showMessageDialog(null,"Co ntacts Table : "+query);
            add(query);
            query = "INSERT INTO business(BName,Department,Profession,AName,MngrNam e,BNotes)values('"+
                setValues.strBName+"','"+setValues.strDepartment+" ','"+setValues.strProfession+"','"+
                setValues.strAName +"','"+setValues.strMngrName+"','"+setValues.strBN otes+"')";

            javax.swing.JOptionPane.showMessageDialog(null,"Bu siness Table : "+query);
            add(query);
            query = "INSERT INTO personals(PName,PDBirth,ADate,PNotes)values('"+
                setValues.strPName+"','"+setValues.strPDBirth+"',' "+setValues.strADate+"','"+
                setValues.strPNotes +"')";

            javax.swing.JOptionPane.showMessageDialog(null,"Pe rsonal Table : "+query);
            add(query);
            query = "INSERT INTO notes(SNotes)values('"+setValues.strSNotes+"')";

            javax.swing.JOptionPane.showMessageDialog(null,"No tes Table : "+query);
            add(query);
    }

    public static void main(String args[]){

        insertIntoDatabase insertintodatabase = new insertIntoDatabase();
    }

}

problem is when i want to execute it every time an error massage occured as --
java.sql.SQLException: No ResultSet was produced
        at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcO dbcStatement.java:259)


 at java.security.AccessController.doPrivileged(Native Method)


but it inserts into the database

So How Can i Stop this be carefull i do not want to stop the message of sqlexception [u]</u>

one more thing i also try to serial execution but it al failed

please i want the solve quickly
Ruzdi


 
Old November 26th, 2007, 12:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you are need to execute DML statements like INSERT, UPDATE, DELETE, etc. you've to use
Code:
executeUpdate()
method of Statement class not the executeQuery() method. executeQuery() method is to run only "select" kind of queries. Try replacing executeQuery() method call with executeUpdate() method.


- Rakesh
 
Old December 5th, 2007, 10:30 AM
yulin11
Guest
 
Posts: n/a
Default

just use your heart,www.codeuu.com

 
Old January 24th, 2008, 06:51 AM
Registered User
 
Join Date: Jan 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey dude i hav done all this things then also i m getting the same error.even i checked the tool.jar file and paste it in /lib.then also it is giving the same error.
plzzzzzzzzz help







Similar Threads
Thread Thread Starter Forum Replies Last Post
Access to audio CDs in Java? Ruth Mackie Java Basics 0 February 13th, 2006 07:15 AM
Name Equality and problems with Java cuskichick Pro JSP 0 June 13th, 2005 12:50 PM
Problems with Java Mail Please advise "Chapter 9" PatrickWalsh JSP Basics 1 September 5th, 2004 06:46 PM
Beginning Java 2 SDK by Ivor Horton problems deviad Java GUI 1 November 27th, 2003 07:38 AM
New to Java, problems compiling Kyle Colyer JSP Basics 3 September 6th, 2003 04:58 AM





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