Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types.
This is my code.
[code]
savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection(url);
String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),text.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();
con.close();
}
catch(ClassNotFoundException ex)
{}
catch(SQLException ex)
{
ex.printStackTrace();
}
}
});
[\code]
[error]
Hi. I want to insert data to ms access but I think I have a prob with data types.
This is my code.
[code]
savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection(url);
String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),tet.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();
con.close();
}
catch(ClassNotFoundException ex)
{}
catch(SQLException ex)
{
ex.printStackTrace();
}
}
});
[\code]
[error]
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'numberinput.getText' in expression.
[\error]
[\error]
15 2119
Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types.
This is my code.
[code]
savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection(url);
String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),text.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();
con.close();
}
catch(ClassNotFoundException ex)
{}
catch(SQLException ex)
{
ex.printStackTrace();
}
}
});
[\code]
[error]
Hi. I want to insert data to ms access but I think I have a prob with data types.
This is my code.
[code]
savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection(url);
String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),tet.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();
con.close();
}
catch(ClassNotFoundException ex)
{}
catch(SQLException ex)
{
ex.printStackTrace();
}
}
});
[\code]
[error]
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'numberinput.getText' in expression.
[\error]
[\error]
Hi,
Please use code tags while posting code. It makes it readable for other people.
Check your query. They way you are calling functions to get values inside query is wrong.
Use Code Tags.
I think your Query string will be like this. -
-
String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
-
It will be something like this.
Good Luck.
Kind regards,
Dmjpro.
Hi,
Please use code tags while posting code. It makes it readable for other people.
Check your query. They way you are calling functions to get values inside query is wrong.
I couldnt figure out what is wrong.Please can you write. - String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(numberinput.getInteger(),nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";
I couldnt figure out what is wrong.Please can you write. - String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(numberinput.getInteger(),nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";
What is this?
Please explain me this!
What is numberinput and getInteger?
Please let me know!
Kind regards,
Dmjpro.
What is this?
Please explain me this!
What is numberinput and getInteger?
Please let me know!
Kind regards,
Dmjpro.
I have an application form with five textfields.
I use numberinput: variable name for textfield for PatientID( PRİMARY KEY)
nameinput : Name(Text)
surnameinput: Surname(Text)
phonenoinput Phone(Number)
Complaint for textpane Complaint( Memo)
I
I have an application form with five textfields.
I use numberinput: variable name for textfield for PatientID( PRİMARY KEY)
nameinput : Name(Text)
surnameinput: Surname(Text)
phonenoinput Phone(Number)
Complaint for textpane Complaint( Memo)
I
So numberinput is your Java variable and getInteger is of it's Member method to retrieve the Integer Number the user inputs.
Right?
I assumed that I posted a solution look above.
And try this and let me know what happens!
:)
Kind regards,
Dmjpro.
So numberinput is your Java variable and getInteger is of it's Member method to retrieve the Integer Number the user inputs.
Right?
I assumed that I posted a solution look above.
And try this and let me know what happens!
:)
Kind regards,
Dmjpro.
I already use [code] numberinput.getInteger [\code]
What I dont understand is why I get this error.
[error]Undefined function 'numberinput.getText' in expression. [/error]
I already use [code] numberinput.getInteger [\code]
What I dont understand is why I get this error.
[error]Undefined function 'numberinput.getText' in expression. [/error]
Hello!
Try this one then let me know whether it errors or not!
:) -
String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
-
And read the Posting Guidelines while you do Post.
Good Luck with your Try. :)
Kind regards,
Dmjpro.
Hello!
Try this one then let me know whether it errors or not!
:) -
String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
-
And read the Posting Guidelines while you do Post.
Good Luck with your Try. :)
Kind regards,
Dmjpro.
I tried it before but it didnt work. I think it is used with Statement. Here I use PreparedStatement so quotes are not needed.
And please can you tell me ( ",' ") what are these quotes used for?
I tried it before but it didnt work. I think it is used with Statement. Here I use PreparedStatement so quotes are not needed.
And please can you tell me ( ",' ") what are these quotes used for?
What it says when you use my Query String?
And try with simple Statement interface.
Good Luck.
Kind regards,
Dmjpro.
What it says when you use my Query String?
And try with simple Statement interface.
Good Luck.
Kind regards,
Dmjpro.
Using quotes creates more confusion. I had compilation errors.
So I took a different approach. ı used conversion methods.
I want to convert PatientID and phone fields ( numberinput and phoneinput).
So I used the method below. -
-
public void AddPatient()
-
{
-
int i=Integer.parseInt(numberinput.getText());
-
-
try{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
con= DriverManager.getConnection(url);
-
-
String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(i,nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";
-
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
-
-
-
-
con.close();
-
-
-
}
-
-
catch(ClassNotFoundException e)
-
{}
-
-
-
catch(SQLException ex)
-
{
-
ex.printStackTrace();
-
}
-
-
}
-
}
-
-
-
Then I got this error.
[ERROR]
va.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
[/ERROR]
Look!
suppose you have a five variables. -
int a,b,c;
-
String d,e;
-
String str_qty = "insert into table_name(AA,BB,CC,DD,EE) values("+a+","+b+","+c+",'"+d+"',"+e+"')";
-
//Now check this code again.
-
//In SQL or Oracle the String should be separated with '' and numbers are not.
-
And your NumberFormatException comes because of invalid String.
As for example 123g this String can't be parsed as Integer.
And here is your Empty String, that's why such Error comes up.
Kind regards,
Dmjpro.
Look!
suppose you have a five variables. -
int a,b,c;
-
String d,e;
-
String str_qty = "insert into table_name(AA,BB,CC,DD,EE) values("+a+","+b+","+c+",'"+d+"',"+e+"')";
-
//Now check this code again.
-
//In SQL or Oracle the String should be separated with '' and numbers are not.
-
And your NumberFormatException comes because of invalid String.
As for example 123g this String can't be parsed as Integer.
And here is your Empty String, that's why such Error comes up.
Kind regards,
Dmjpro.
I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getText' and now I get insert syntax error. -
-
public void AddPatient()
-
{
-
-
-
-
try{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
con= DriverManager.getConnection(url);
-
-
String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
-
st= con.createStatement();
-
-
st.execute(sqlStatement);
-
-
con.close();
-
-
-
I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getText' and now I get insert syntax error. -
-
public void AddPatient()
-
{
-
-
-
-
try{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
con= DriverManager.getConnection(url);
-
-
String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
-
st= con.createStatement();
-
-
st.execute(sqlStatement);
-
-
con.close();
-
-
-
Hi,
I will again suggest you to check your query. It is wrong. Check the quotes(') you have put in the query. they are not matching.
I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getText' and now I get insert syntax error. -
-
public void AddPatient()
-
{
-
-
-
-
try{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
con= DriverManager.getConnection(url);
-
-
String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
-
st= con.createStatement();
-
-
st.execute(sqlStatement);
-
-
con.close();
-
-
-
Ok!
These type of expression I don't know you getting from.
Make sure that whether your Syntax is Ok or not.
Kind regards,
Dmjpro.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Egyd Csaba |
last post by:
Hi,
I've a problem with some of my stored procs. My config is: RH7.1, Postgres
7.3.2
I had converted a few fields of a few tables from one type to another and
after this I made all the...
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: Mr. SweatyFinger |
last post by:
WHY CAN'T THE CLOWN -HOLES WHO WROTE ASP.NET PROVIDE AN ERROR LINE
NUMBER???
HONEST TO SH@THOLE PETE
Server Error in '/New Folder (7)' Application....
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I...
|
by: imaloner |
last post by:
I am posting two threads because I have two different problems, but both have the same background information.
Common Background Information:
I am trying to rebuild code for a working,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
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...
| |