Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:05:19+00:00 2026-06-13T22:05:19+00:00

I have developed an awt program and now i am trying to connect it

  • 0

I have developed an awt program and now i am trying to connect it to the MS Access Database using ODBC bridge.

Here is the code :-

import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;

class MyClass
{
  public static void main(String args[])
  {
     Project prj=new Project();
  }
}

class Project
{
Statement s;
Connection con;
String s1,s2;
TextField t1,t2;
Button b1,b2;

Project()
{
Frame f=new Frame("Registration");
f.setLayout(new GridLayout(2,1));
f.setSize(400,400);

Panel p1=new Panel();
p1.setLayout(new FlowLayout());
t1=new TextField(15);
t2=new TextField(30);
p1.add(new Label("Roll :"));
p1.add(t1);
p1.add(new Label("Name :"));
p1.add(t2);
f.add(p1);

Panel p2=new Panel();
p2.setLayout(new FlowLayout());
s1=t1.getText();
s2=t2.getText();

try{
   try
      {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      }
       catch(Exception e){}
   con=DriverManager.getConnection("jdbc:odbc:testdb");
   s=con.createStatement();
   }catch(SQLException e){System.out.println("Error in connecting to database"); }

b1=new Button("Submit");
b1.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
  try{
 s.executeUpdate("insert into college(Roll,Names) values("+Integer.parseInt(s1)+","+s2+")");        
  }catch(SQLException se){
  System.out.println(se);}
}});
b2=new Button("Quit");
 b2.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){System.exit(0);
   }});
p2.add(b1);
p2.add(b2);
f.add(p2);
f.pack();

    f.setVisible(true);
}
}

When i use the following statement in the actionListener

 s.executeUpdate("insert into college(Roll,Names) values (555,'Naveen')");

the values are inserted into the database.But when i use the statement,which now takes values from the textfield,

s.executeUpdate("insert into college(Roll,Names) values ("+Integer.parseInt(s1)+","+s2+")");

as used in the above code,i am getting the exception ,which i catch using the try catch block.

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

There is definitely something wrong in the sql statement .Where am i wrong???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:05:20+00:00Added an answer on June 13, 2026 at 10:05 pm

    wrap your s2 inside inside single quotes(”) as you were doing in your first insert statement.

    try this:

    s.executeUpdate("insert into college(Roll,Names) values ("+Integer.parseInt(s1)+",'"+s2+"')");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a website using Razor (Microsoft WebMatrix) and now I want to
This is my code I have developed. This is the main program which holds
Have developed a small Windows application using SQL Server as its database. I need
I have developed an application using J9 that runs in windows mobile. but now
I have developed a J2ME app using java.awt.Window as I want a full screen
I have developed a project using MVC3 and Code first Entity Framework 4.0 as
I have developed sample api as jar file. This jar file contains the code
I have developed a Java server using Eclipse that accepts TCP socket connection from
I have developed a Facebook application using Flash as3. In this application when ever
I have developed a utility in Java using the Financial Information eXchange(FIX) protocol to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.