Home Answers Viewqa JDBC java database error

 
 


prashant
java database error
1 Answer(s)      4 years and 2 months ago
Posted in : JDBC

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 Pages:
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.
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
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
error
of framework used and also the JDK version. This type error also comes when java file is complied in old version of java and used on latest version. Thanks
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 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
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
error come
error come  com.techi.bean.Employee cannot be cast... each attribute  Here is the code that retrieve the values from database... database. 1)EmpBean.java: package form; import java.sql.*; import java.util.
error - JDBC
,i got a errors d:temp> java DBConnect db Connect Example... to the database"); conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { e.printStackTrace
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
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...); // Load the database driver Class.forName
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
programming error - Java Beginners
) { out.println("Database Error :"+se.getMessage()); } catch(Exception e... should get saved in the database . and how to calculate the no.of characters
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
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
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
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
Compilation error in java - Java Beginners
Compilation error in java  i have a properties file named "connecton.properties" which has details about database server connection. when i load i that file in java class,my code is Properties props = new Properties(); File
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 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  
database
database  im doing my project in netbeans swings...wn a user wants to create a database from the gui...i want to display an error msg if a database with that name already exists and if it does not exist new database should
Java compilation error - JSP-Servlet
Java compilation error  Hi, im trying to do a report creation using... are stored in database(sql), the file attachment also will be kept in the server and also in database for reference according to the report identification.. So
Database
Database  In MYSQL database i m given as the email id as the char but i enter the email id it gives manually error.how can i recover that error   For email, use the data type varchar
database
database  I wanted to know if it is possible to establish database connection on a remote pc with mysql using java swings from netbeans and then create a database on the remote pc.... Kindly help me
DATABASE
DATABASE  How can i get combo box values from database?? or how can i get values in the drop down menu of the html which is similar to dat of combo box in java - from database
Database
Database  How to represent data from database in a tree?   Please visit the following link: Retrieve data from database in tree using Java Swing
database
links: Connect JSP with database Mysql Connect Java with database Mysql...database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover
database
links: Connect JSP with database Mysql Connect Java with database Mysql...database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover
database
links: Connect JSP with database Mysql Connect Java with database Mysql...database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover
Database
Database  from java code i have to retrieve some data from a database, which is present in a different timezone. Scenario :- My database... in database timezone is 9PM 15APR2012. I want to retrieve something from database
database
database  Im doing my project in java swings...netbeans I wanted java source code to establish connection to postgresql_8.1 using jdbc and create a user defined database and a table in that database and insert values Plz help me
database
database  Can you please help me to establish database connection to ms sql 2000 from java swing in netbeans
Connecting to MYSQL Database in Java
from database"); } catch (Exception e) { System.out.println("Error...Connecting to MYSQL Database in Java  I've tried executing the code below but the error that I get is "Error: com.mysql.jdbc.Driver" I downloaded
database
database..im doing my project in java swings.....netbeans Kindly help me ThankYou...database  I want to let the user select one of the database type... give the name of the database name that he want to create in a textfield
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
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... String strDataSource = "java:comp/env/jdbc/HTHLogDB"; ic = new InitialContext
database
, dob date default NULL, PRIMARY KEY (id) ); i got error...; Have you run this query directly into the Mysql database? Here it works properly.   Have you run this query directly into the Mysql database? Here
Java Compilation error - Development process
product ODBC,,,i want directly to upload a .xls file intlo remote database in java...Java Compilation error  hi my serious problem is,how can i upload a file directly to the current remote database.. Below steps might work. 1
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect...();} And i am getting this error java.sql.SQLException: [Microsoft][ODBC
database
of combo box in java - from database? you had given me the answer <%@page...database  How can i get combo box values from database?? or how... name officename and database name jsw   <%@page import="java.sql.
database
database  i am created one table in mysql database with one of the column name is emailid.now i want to write a java code that if the mail id... or not. If it is already exist in database, then show a message 'Already exists
java runtime error: JDBC code - Java Beginners
java runtime error: JDBC code  Hi i want to insert data into mysql database in my local system. I installed mysql5.0 and using mm.mysql-2.0.4-bin.jar and also set in the class path. the code is compilled and giving runtime error
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect...){e.printStackTrace();} And i am getting this error java.sql.SQLException
java compilation error - JSP-Servlet
java compilation error  i want to do client side validations using JSP, so please can u suggest me a way out.thanq very much for the previous answers... to add a user in database. If submit the form then no field inserted blank.You
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
JSP Error - JSP-Servlet
error. HTTP Status 500... description The server encountered an internal error () that prevented it from fulfilling...; ====================== Java Class=dataAccessBean.java package com.ziaur; import java.sql.
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.