java


JavaFX - Insert form textfield to SQLite Database


I made a Form scene in my Application and wanted to insert the entered data to my SQLite Database when I hit the Save button. Here is the short code:
#FXML
private void handleSaveNewShop(ActionEvent event) {
String name = shopname.getText();
String adress = streetadress.getText();
String city = cityname.getText();
String state = statename.getText();
String country = countryname.getText();
String zip = zipcode.getText();
String phonept1 = phonecountryid.getText();
String phonept2 = phoneareaid.getText();
String phonept3 = phoneothernumber.getText().toString();
Connection conn = null;
Statement stmt = null;
try{
Class.forName("org.sqlite.JDBC");
System.out.print("\nConnecting to database...");
conn = DriverManager.getConnection("jdbc:sqlite:FranchiseManagement.sqlite");
System.out.println(" SUCCESS!\n");
/*Tried this
String insertToshopList = "INSERT INTO shopList (name, adress, city, state, country, zipcode, phonect, phonearea, phonemain)" + "values(name,adress,city,state,country,zip,phonept1,phonept2,phonept3)";
stmt.executeUpdate(insertToshopList);
*/
//And This
//stmt.executeUpdate( "INSERT INTO shopList ('name','adress','city', 'state', 'country', 'zipcode', 'phonect', 'phonearea', 'phonemain') VALUES('"+name+"','"+adress+"','"+city+"'),'"+state+"','"+country+"','"+zip+"','"+phonept1+"','"+phonept2+"','"+phonept3+"'");
conn.commit();
System.out.println(" SUCCESS!\n");
conn.close();
} catch(SQLException se) {
se.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
But I got NullPointException on my commited parts. The database connection seems okay and Connected.
Here is how my Database Looks:
Fixed it by removing the commit and added the INSERT into method well-formatted:
#FXML
private void handleSaveNewShop(ActionEvent event) {
String name = shopname.getText();
String adress = streetadress.getText();
String city = cityname.getText();
String state = statename.getText();
String country = countryname.getText();
String zip = zipcode.getText();
String phonept1 = phonecountryid.getText();
String phonept2 = phoneareaid.getText();
String phonept3 = phoneothernumber.getText();
Connection conn;
Statement stmt = null;
try{
Class.forName("org.sqlite.JDBC");
System.out.print("\nConnecting to database...");
conn = DriverManager.getConnection("jdbc:sqlite:FranchiseManagement.sqlite");
System.out.println(" SUCCESS!\n");
stmt = conn.createStatement();
stmt.executeUpdate( "INSERT INTO shopList ('name','adress','city', 'state', 'country', 'zipcode', 'phonect', 'phonearea', 'phonemain') VALUES('"+name+"','"+adress+"','"+city+"','"+state+"','"+country+"','"+zip+"','"+phonept1+"','"+phonept2+"','"+phonept3+"')");
//conn.commit();
System.out.println(" SUCCESS!\n");
conn.close();
} catch (ClassNotFoundException | SQLException e){
Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, e);
}

Related Links

Can I use Amazon Kinesis Connectors to send a stream to two destinations (two emitters)?
Junit Tests failing when running it through jenkins
Collision method gone crazy;
Getting the (starting) X and Y coordinates of a Path2D shape drawn on Jpanel
Unable to execute java class file from php exec method?
Google Map not display on the Mobile Screen in Android
Debug Exception Breakpoints in multiple sub packages
JavaFX Deploying with other JavaFX projects
Does GAE jdo not support identity strategy=“timestamp”
Case insensitive JSON to POJO mapping without changing the POJO
JPA | EclipseLink Left outer Join
Correct way of Encrypting and Decrypting an Image using AES
Simple Android App not working [duplicate]
Return specified number of words before and after given position in text
Java class which requires using interface if you want to use it's method
SSL Certificate in Spring Boot

Categories

HOME
client
listview
coq
google-oauth
rubygems
rdf
datastax-java-driver
pheatmap
handsontable
size
ups
pc
finite-automata
django-cms
visual-composer
visjs
object-detection
restful-authentication
emgucv
microsoft-sync-framework
buildbot
centos6.5
poltergeist
facebook-access-token
maxmind
primitive
directx-10
key-value-observing
scorm2004
grails-3.1
catch-all
webtest
asset-pipeline
language-concepts
vxworks
web-mining
sas-visual-analytics
email-templates
avro4s
fakeiteasy
import-from-excel
gpx
network-flow
revapi
dds
lowpass-filter
drupal-6
csound
tactic
np-complete
sqldf
jspdf-autotable
deadbolt-2
httplistener
paypal-express
clang-static-analyzer
angstrom-linux
flash-cs5
moveit
hill-climbing
apachebench
goose
xna-4.0
lib.web.mvc
collapse
browser-bugs
graph-drawing
createprocessasuser
lustre
dia
gwidgets
jsonpickle
c3
gadt
java.util.concurrent
poller
viadeo
flexmojos
gnu-smalltalk
mysqltuner
access-rights
dir
jplaton
eclipse-memory-analyzer
shellexecute
pushbackinputstream
cisco-jtapi
dotnethighcharts
punbb
appendto
iphone-web-app
datareader
h.323
dbal
brewmp
boost-smart-ptr
simpletest
project-hosting
ajax-forms
ntvdm.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App