java database error

java database error

View Answers

April 7, 2009 at 12:41 PM

hi prashant,

Use the following code to insert the data into MS-Access database:

import java.sql.*;
import java.math.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

public class InsertData extends JFrame implements ActionListener {

JButton insertButton;
JTextField text1,text2;
JLabel label1,label2,label;
JPanel p1,p2,p3,panel;

public InsertData(){
insertButton = new JButton("Insert");
insertButton.addActionListener(this);
text1 = new JTextField(15);
text2 = new JTextField(15);

label1 = new JLabel("Name:");
label2 = new JLabel("Address:");
label = new JLabel("",JLabel.CENTER);

p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
panel = new JPanel();
p1.add(insertButton);
p3.add(label);
panel.setLayout(new GridLayout(2,1));
panel.add(p3);
panel.add(p1);

p2.setLayout(new GridLayout(2,1));
p2.add(label1);
p2.add(text1);
p2.add(label2);
p2.add(text2);

this.getContentPane().add(p2,"Center");
this.getContentPane().add(panel,"South");
this.setSize(300,150);
this.show();
}
public static void main(String args[]){
InsertData data = new InsertData();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==insertButton)
{
PreparedStatement pstm;
ResultSet rs;
String sql;
if((text1.getText().equals("")&&(text2.getText().equals("")))){
label.setText("Please enter the textfields.");
}
else{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connect =DriverManager.getConnection("jdbc:odbc:access");
pstm=connect.prepareStatement("insert into data values(?,?)");
pstm.setString(1,text1.getText());
pstm.setString(2,text2.getText());
pstm.executeUpdate();
label.setText("Data is inserted into MS Access database");
pstm.close();
connect.close();
}
catch(Exception ex){
System.out.println(ex);
}
}
}
}
}

Thanks









Related Tutorials/Questions & Answers:
java database error - JDBC
java database error  hi all i am writing one swing application where i want to insert data into database(MS-Access) but dont know how to do... the following code to insert the data into MS-Access database: import java.sql.
Database error - WebSevices
Database error  Hello, How i connect my database file& tables to Zend library file Using PHP language. In which library file i should change that code. Any one know the exact changes. Tell me.   http
Advertisements
Applet to database error - Applet
Applet to database error  Hi... I had an application where i need to connect to the database for the values to display in the applet.... Following... necessary for finding the error... as itz only drawing strings or lines
error oracle database connection?
error oracle database connection?  hi now i am trying to connect oracle database and also insert my data into table, but it's not working.. I created... method stub } } desing jsp page; newuser_reg.jsp <%@ page language="java
Database Error - Hibernate
Database Error  Hi, I am working with Struts 1.2---- AJAX-----Hibernate 3.0 --- MySQL 5.0. At the time of inserting/fetching from Database... exceeded; try restarting transaction That means the database becomes locked. Can
Error with LogIn with mysql database
Error with LogIn with mysql database  Hi, I have followed steps from your tutorial titled SpringMVClogin with database. I am not using Jetty, as I... 404 page error. In Tomcat console it states the reason as: "Error creating bean
connection database error
connection database error  import java.awt.EventQueue; // import packages import java.awt.event.ActionEvent; import java.awt.event.ActionListener...;which type of error occurs? Specify it. Is NWIND is your dsn
Oracle Database error - JDBC
Oracle Database error   String query11 = "SELECT product_code, product_quantity, price FROM o"+orderid; ResultSet rs11 = stmt.executeQuery(query11); while(rs11.next()){ product_code[j
error log and send Database
error log and send Database  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details
error in accessing database - JSP-Servlet
error in accessing database  hiiii im tanushri im tryng to connect my database to the servlet i hv succeeded in connectivity but im stuck to nother error called Got minus one from read call although i hv feeded data to my
Display error message if data is already inserted in database
Display error message if data is already inserted in database   Display error message if data is already inserted in database Pls help me Thanks
getting error while inserting values in database
) { out.println("An Error Had occurred while accessing the database...getting error while inserting values in database  AddUser.java...(); Context envContext = (Context) initContext.lookup("java:/comp/env
Java error
Java error  class WhileLoopMethod{ public static void main(String args[]){ new Hello(); } } class Hello{ int a = 5, b = 88; while(a } //it is giving compile time error .....illegal start
Java error
Java error  class WhileLoopMethod{ public static void main(String args[]){ new Hello(); } } class Hello{ int a = 5, b = 88; while(a } //it is giving compile time error .....illegal start
jQuery auto complete through database using JSP shows error
jQuery auto complete through database using JSP shows error  The tutorial on jQuery titled "jQuery auto complete through database using JSP" shows error on browser when I try to select the one in the dropdown. Please help
error in uploading image from jsp to oracle 10g database
try to insert into the image into the database i got the above error please advice how to get rid of error   JSP upload image in Mysql database...error in uploading image from jsp to oracle 10g database  
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has... it in the code. but still i am getting the error in the update query. please provide
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)  how do i implement connection pooling... static final String strDataSource = "java:comp/env/jdbc/HTHLogDB"; ic = new
java compilation error - Hibernate
java compilation error  hi, i have made an registration page whosevalues should be inserted into database. i have used hibernate and eclipse... the corresponding database in the sql(of course u should install your sql setup
trap error - Java Beginners
trap error  Hello. Am trying to trap this error that appears when i post blank fields to database. "[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression". what i want is a message cannot post
java error - JDBC
java error  Why am I getting errors in the follwing program...,password); System.out.println("Connected to the database"); conn.close(); System.out.println("Disconnected from database"); } catch
trap error - Java Beginners
trap error  Hello. Am trying to trap this error that appears when i post blank fields to database. "[Microsoft][ODBC Microsoft Access Driver] Data...); // Load the database driver Class.forName
Database,Java
Database,Java  help me for the following things if one customer... me the how to write the query in MySQL database and i want coding for this one in Java.because i am using Java as the front end.   1)page.jsp: <
java database
java database  help me with this...i never learn build java database... to design and implement objects needed for a program that maintains a database.../teacher information, search it, alter it, etc. The database is maintained as a list
programming error - Java Beginners
(SQLException se) { out.println("Database Error :"+se.getMessage()); } catch(Exception e... and similarly should get saved in the database . and how to calculate
Java Error - Java Beginners
Java Error  Hello Sir ,How i Can solve Following Error Can not find Symbol - in.readLine(); Here Error Display at in  Hi Friend, It seems that you haven't defined the object 'in'.Anyways, Send your code so that we
java and database
java and database  sir i want to prepare a sign in form and i want to check that user name is exist or not in database if it is exist in database...("")) { JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE
runtime error in java
runtime error in java  What is Run time error in Java?   Run time error is a syntax error that during the execution of a program.It hash different types of a program like as Logic error,Fatal Errors,source code,wrong
pointer error java
pointer error java  How to catch null pointer errors in java if the if(value != null) or null
java error - Java Beginners
java error  Hello sir, on compiling any program from command prompt.... But if I want to run that program the fetches me the following error. For example for file: Test.java C:\Program Files\Java\jdk1.6.0_17\bin>javac Test.java
java error - Java Beginners
java error  G:\threading>javac threadmethods.java Note: threadmethods.java uses or overrides a deprecated API. Note: Recompile with -Xlint... been obsoleted. To get the details of your error, compile your class with Xlint
java compilation error - Applet
java compilation error  I am getting compilation error in the following code.: public void paint(Graphics g) { switch(screen...; } } Error is: Illegal start of expression Plz. find why am I getting this error
Java Error - Java Beginners
Java Error  E:\SUSHANT\Core Java\FileHandling\Error>javac... ch= reader.read(); ^ 1 error import java.io....); //System.out.println("Enter characters, 'q' to quit."); try
Java Error - Java Beginners
Java Error  Here Error near Read Method import java.util.*; import java.io.*; public class inputdemo { public static void main(String[] args) throws IOException { String bookname,author; float price; System.out.println
JAVA Annotation Error
JAVA Annotation Error  while compiling simple java program i get annotation error i.e class will only be accepted if annotation processing is explicitly requested..how to solve
java runtime error - JDBC
java runtime error  when i m running my program by using jdk1.6.0 then it is giving the error of classunsupported major.minor version 50.0.to remove... version error 49.0.so, please suggest how will i compensate this problem
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
db error - Java Beginners
db error  Hi, how to insert text area content into database...(null,"Data is successfully inserted into the database." ); st.close...' or 'longtext' datatype for the textarea field in the database table. Thanks
java error - Java Beginners
java error  Thanks for providing me the answer for the question... be dereferenced If Programme saved in SortFileData also shows some error Please rectify the errors and provide the coding that run properly Write a Java program
java runtime error - JDBC
java runtime error  when i m running my program using type1 driver it is showing a runtime error of SQLException of unable to create the connection object.please give the solution
error - Java Beginners
Java error handling  How to write a code to handle the errors in Java?  hi all,visit these site mentioned belowhttp://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Windows_XP.htmlit will work
JAVA Error - Java Beginners
JAVA Error  i have made my own calculator GUI..and i want the text..."); btnBack.setForeground(red); it send me an error message that goes like this unknown...: http://www.roseindia.net/java/ Thanks.   Hello Just use
error message - Java Beginners
error message  sir, while i m trying to execute my first program(print my name)I get error message like" javac is not recognized as internal...;Hi friend, To compile and run a java program we need to install java
java compilation error - Applet
java compilation error  hi friends the following is the awt front design program error, give me the replay E:\ramesh>javac...://www.roseindia.net/java/example/java/awt/ Thanks
what is the error - Java Beginners
what is the error  What is the compile time error that i am getting... is creating the compile time error such as : - ? CANNOT FIND SYMBOL ? because you... this .correct code is this if you don?t want such type of error EG : - import java.lang.
java error - Java Beginners
java error  Dear roseindiamembers, I have checked the registration form for new user to login roseindiamembers forum with different data.It's not working properly .when i am registering as new user in http
Java Error - Java Beginners
Java Error  import java.io.*; import java.lang.*; public class Wrapperdemo { float prin; float rate; int no; float interest; Wrapperdemo() { try{ BufferedReader br = new BufferedReader(new InputStreamReader
java runtime error - JDBC
java runtime error  when i am running my jdbc program using thin driver this error is coming at runtime: Exception in thread "main..., give me the suggesion yo solve this problem  This kind of error due
runtime error - Java Beginners
runtime error  I created a sample java source ,compiled it succesfully using command prompt but when i tried to run i got the folowing error " Exception in thread "main" java.lang.UnsupportedClassVersionError" I have set
Error with PrintDocument - Java Beginners
Error with PrintDocument  Error: StudRec.java:526: printComponent(java.awt.Component) in PrintableDocument cannot be applied.... Note: Recompile with -Xlint:unchecked for details. 1 error

Ads