Error in Java Statement when inserting into MS Access DB

Joined
Aug 3, 2007
Messages
2
Reaction score
0
Hello

I have a problem when coding the statement

Code:
PHP:
stmt.execute("insert into Member values ('+mname+' ,'+mail+','+tel+')");
where mname, mail,tel are variables
which the user inputs them and stored in variables and then i want them to be stored in MS Access, everything is done successfully until it reached the previous statement

Here is the code
PHP:
try {
            
            System.out.println("Beginning Connection");
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String accessFileName = "jdbc:odbc:Project";
            String connURL = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="+accessFileName+".mdb;PWD=";
            Connection con = DriverManager.getConnection( accessFileName); 
            Statement stmt = con.createStatement();
            System.out.println("Connection done successfully");
            stmt.execute("Create table Member(Name String,EMAIL String,Telephone String)");
            System.out.println("Table Created");
            
            System.out.println("Please, Enter the Member Name : ");
            InputStreamReader istream = new InputStreamReader (System.in);
            BufferedReader br = new BufferedReader (istream);
            
            try{
            String  mname= (br.readLine());
                
                System.out.println("Please, Enter the E-Mail Address : ");
                InputStreamReader isr = new InputStreamReader (System.in);
                BufferedReader bfr = new BufferedReader (isr);
                
                try
            {
             String mail= (bfr.readLine());
                try{
                    
                System.out.println("Please, Enter the Telephone number : ");
                InputStreamReader ism = new InputStreamReader (System.in);
                BufferedReader bb = new BufferedReader (ism);
            
            String tel=String.valueOf(bb.readLine());
            stmt.execute("insert into Member values ('+mname+' ,'+mail+','+tel+')");
            System.out.println("Insertion has been completed");
            stmt.execute(" select * from Member");
            ResultSet rs=stmt.getResultSet();
            
            if (rs != null)
                while (rs.next()){
                    System.out.println("Name: "+rs.getString("Name")+ "  E-MAIL: " + rs.getString("EMAIL")+" Telephone: "+rs.getString("Telephone")); 
                }
                
            stmt.close();
            con.close();
                
                
            }
        
            catch (IOException err)
                {
                    
                System.out.println("Error in reading the numbers");
            }
        
            }
        
            catch (IOException err)
                {
                    
                System.out.println("Error in reading the numbers");
            }
                
            }
            catch (IOException err)
                {
                    
                System.out.println("Error in reading the numbers");
            }
            
        }
 
 
            catch (Exception err) {err.printStackTrace();}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top