Hi All,
I can't insert java variable into ms access database.
I'm using odbc connection to ms access.
Below are my coding. -
try
-
{
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
// set the connection for database path
-
String Database_Path = "E:/Segi/Project/Coding/Car_Park_Storage.mdb";
-
String Storage = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
-
Storage+= Database_Path.trim() + ";DriverID=22;READONLY=true}";
-
Connection Connect = DriverManager.getConnection( Storage ,"","");
-
Statement Insert = Connect.createStatement();
-
//int date_in = Integer.parseInt(Show_Date_In);
-
//int times_in = Integer.parseInt(Show_Times_In);
-
Insert.execute("insert into Daily_Details values(Car_Number,Parking_Lot,'13','14','345','345','456','3456');");
-
-
Insert.close();
-
Connect.close();
-
}
-
When I change the variable to values like ('11','12','13' ,'14','345','34 5','456','3456' );");
It able to insert into access.
Kindly please help look into the problem.
Thanks and Regards,
Crispin Yeap
2 6102 Dököll 2,364
Recognized Expert Top Contributor
Hey there good buddy!
Looks like a great written code but I cannot see what the problem is. The only solution I have for you is giving something that works for me:
JavaBean: -
package foo;
-
-
/**
-
* @author Dököll
-
*
-
*/
-
-
import java.io.*;
-
import java.sql.Connection;
-
import java.sql.DriverManager;
-
import java.sql.Statement;
-
import java.sql.ResultSet;
-
-
public class AddBean {
-
-
private String EmployeeID;
-
private String UserID;
-
-
private String LastName;
-
private String FirstName;
-
-
private String Title;
-
private String TitleCourtesy;
-
-
private String BirthDate;
-
private String HireDate;
-
-
private String Address;
-
-
private Connection connection = null;
-
private ResultSet rs = null;
-
private Statement st = null;
-
String connectionURL = "jdbc:odbc:Northwind";
-
-
public AddBean() {
-
try {
-
// Load the database driver
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
// Get a Connection to the database
-
connection = DriverManager.getConnection(connectionURL, "root",
-
"root");
-
} catch (Exception e) {
-
System.out.println("Exception is ;" + e);
-
}
-
-
}
-
-
public void setUserID(String UserID) {
-
this.UserID = UserID;
-
}
-
-
-
-
public String getUserID() {
-
return (this.UserID);
-
}
-
-
-
public void SendInTheClowns() {
-
-
try {
-
String sql = "insert into Employees(EmployeeID, UserID,LastName, FirstName, Title, TitleCourtesy,BirthDate, HireDate, Address )values('"
-
+EmployeeID + "','" + UserID + "','" + LastName + "','" + FirstName + "','" + Title + "','" + TitleCourtesy + "','" + BirthDate + "','" + HireDate + "','" + Address + "')";
-
Statement s = connection.createStatement();
-
s.executeUpdate(sql);
-
s.close();
-
} catch (Exception e) {
-
System.out.println("Exception is ;" + e);
-
}
-
}
-
-
public String getEmployeeID() {
-
return EmployeeID;
-
}
-
-
public void setEmployeeID(String employeeID) {
-
EmployeeID = employeeID;
-
}
-
-
public String getLastName() {
-
return LastName;
-
}
-
-
public void setLastName(String lastName) {
-
LastName = lastName;
-
}
-
-
public String getFirstName() {
-
return FirstName;
-
}
-
-
public void setFirstName(String firstName) {
-
FirstName = firstName;
-
}
-
-
public String getTitle() {
-
return Title;
-
}
-
-
public void setTitle(String title) {
-
Title = title;
-
}
-
-
public String getTitleCourtesy() {
-
return TitleCourtesy;
-
}
-
-
public void setTitleCourtesy(String titleCourtesy) {
-
TitleCourtesy = titleCourtesy;
-
}
-
-
public String getBirthDate() {
-
return BirthDate;
-
}
-
-
public void setBirthDate(String birthDate) {
-
BirthDate = birthDate;
-
}
-
-
public String getHireDate() {
-
return HireDate;
-
}
-
-
public void setHireDate(String hireDate) {
-
HireDate = hireDate;
-
}
-
-
public String getAddress() {
-
return Address;
-
}
-
-
public void setAddress(String address) {
-
Address = address;
-
}
-
}
-
Your JSP -
-
<%@ page language="java"
-
pageEncoding="ISO-8859-1"%>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-
-
-
<%@ page import="java.sql.*"%>
-
<title>Submit form...</title>
-
</head>
-
-
<body bgcolor="#ffccff">
-
<h1>Submit form</h1>
-
<form name="form1" method="POST" action="">
-
-
EmployeeID: <br><input
-
type="text" name="employeeID"> <br>
-
User ID:<br><input type="text" name="userID"> <br>
-
-
Last Name: <br><input
-
type="text" name="lastName"> <br>
-
First Name:<br><input type="text" name="firstName"> <br>
-
-
Title: <br><input
-
type="text" name="title"> <br>
-
Title Courtesy:<br><input type="text" name="titleCourtesy"> <br>
-
-
Birth Date: <br><input
-
type="text" name="birthDate"> <br>
-
Hire Date:<br><input type="text" name="hireDate"> <br>
-
-
Address: <br><input
-
type="text" name="address"> <br>
-
<br>
-
<input type="submit" value="Submit">
-
<jsp:useBean id="sample" class="foo.AddBean" scope="page">
-
<jsp:setProperty name="sample" property="*" />
-
</jsp:useBean></form>
-
-
-
<%
-
sample.SendInTheClowns();
-
%>
-
-
-
</body>
-
</html>
-
I'll tell ya, this works like waterfalls, sure you'll need to modify to your access database fields to relate to TEXT rather than Number, but, you should be good to go...
You'll need to creat an ODBC connection called Northwind or anything you want:
(1) Control Panel
(2) Administrative Tools
so on and so forth:-)
Gotta go now, hope this works:-)
1.) You must wrap the values around single quotes when inserting data into character columns in the database. That's why ('11','12','13' ,'14','345','34 5','456','3456' ); works. Using a PreparedStateme nt takes care of the problem.
2.) What are Car_Number and Parking_Lot? Are they supposed to be variables holding the actual values?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Nikhil Barthwal |
last post by:
Hi,
I have a Java program that needs to access the value of variable
PATH (Set in Unix enviroment by setenv or DOS enviroment by PATH
statement). How do I access it in Java?
Thanks in advance,
Nikhil
|
by: Nelson Broat |
last post by:
In jsp land you can have the following:
<%
String name = "Nelson";
%>
Hi, my name is <%= name %>.
Such that, in your browser you see:
|
by: 2BaCook |
last post by:
Hi, I have an Access database that I am creating a java front end to.
I am trying to insert a record into a table and get a problem whenever
I try to insert into my "Number" column.
Here is my table schema:
Column 1 Name: Number Type: VARCHAR
Column 2 Name: Street Type: VARCHAR
Column 3 Name: Phone Type: VARCHAR
Column 4 Name: Comments Type: LONGCHAR
Column 5 Name: Pets Type: VARCHAR
|
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete examples?
|
by: etuncer |
last post by:
Hello All,
I have Access 2003, and am trying to build a database for my small
company. I want to be able to create a word document based on the data
entered through a form. the real question is this: can Access create
the document and place it as an OLE object to the relevant table?
Any help is greatly appreciated.
Ricky
| |
by: ak1dnar |
last post by:
There is a Error getting while i am entering records using this jsp file.
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="../Connections/conn.jsp" %>
<%
// *** Edit Operations: declare variables
// set the form action variable
String MM_editAction = request.getRequestURI();
if (request.getQueryString() != null && request.getQueryString().length() > 0) {
|
by: techbuddha |
last post by:
Hi new to the forum and visual basic.
I am attempting to fix a migration of excel to access. The excel sheets where simple copied as is into access. for example one table lists the academic history from elementary to phd and on to post doctoral work alll on the same row. I want to break that up to have each level of education as a seperate record and then relate that back to the person.
i can pull the data into a recordset
I can...
|
by: Sanny |
last post by:
I have an app in Java. It works fine. Some people say Java works as
fast as C. Is that true?
C can use assembly language programs. How much faster are they inplace
of calling general routines.
Can C++ directly acess the Registers.
Will the Computation 5-10 times faster than Java?
|
by: vijaykumardahiya |
last post by:
Hello Sir,
I have a simple Issue but It is not resolve by me i.e input parameter
are not store in Ms-Access.
I store the input parameter through Standard Action <jsp:useBean>.
jsp:useBean call a property IssueData. this property exist in
SimpleBean which create a connection from DB and insert the data.
At run time servlet and server also show that loggging are saved in DB.
But when I open the table in Access. Its empty.
Ms-Access have...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |