Can't insert UUID in to Embedded Database [duplicate]2019 Community Moderator ElectionPostgres UUID JDBC not workingWhy can't I use switch statement on a String?How to get the insert ID in JDBC?Connect Java to a MySQL databaseCan't execute jar- file: “no main manifest attribute”How to pass user define table type of sql server as a parameter to a store procedure from javaCan't start Eclipse - Java was started but returned exit code=13Mysql Syntax error while inserting from Servlet using preparedstatementJava Sequential UUIDError while saving spark Dataframe in hbase using phoenix in SparkRINSERT INTO Statement automatically adds thousand separators to java integer starting at 1000k

PTIJ: Who should pay for Uber rides: the child or the parent?

What is this large pipe coming out of my roof?

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

Unreachable code, but reachable with exception

How do anti-virus programs start at Windows boot?

What is IP squat space

Employee lack of ownership

It's a yearly task, alright

Bash: What does "masking return values" mean?

Know when to turn notes upside-down(eighth notes, sixteen notes, etc.)

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver

Instead of Universal Basic Income, why not Universal Basic NEEDS?

Possible Leak In Concrete

2D counterpart of std::array in C++17

How to generate globally unique ids for different tables of the same database?

An Accountant Seeks the Help of a Mathematician

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

Making a sword in the stone, in a medieval world without magic

Can hydraulic brake levers get hot when brakes overheat?

How to make healing in an exploration game interesting

Informing my boss about remarks from a nasty colleague

How to answer questions about my characters?

Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?

How to deal with taxi scam when on vacation?



Can't insert UUID in to Embedded Database [duplicate]



2019 Community Moderator ElectionPostgres UUID JDBC not workingWhy can't I use switch statement on a String?How to get the insert ID in JDBC?Connect Java to a MySQL databaseCan't execute jar- file: “no main manifest attribute”How to pass user define table type of sql server as a parameter to a store procedure from javaCan't start Eclipse - Java was started but returned exit code=13Mysql Syntax error while inserting from Servlet using preparedstatementJava Sequential UUIDError while saving spark Dataframe in hbase using phoenix in SparkRINSERT INTO Statement automatically adds thousand separators to java integer starting at 1000k










0
















This question already has an answer here:



  • Postgres UUID JDBC not working

    4 answers



I have been trying to insert data from an app to a database, but always get a syntax error relating to a UUID number that will be the customer's ID, and primary key for the table. The column is set as BIGINT, it always returns. Here is the code:



String a = txtNombre.getText();
String b = txtApellido.getText();
String c = txtLetras.getText();
String d = txtFin.getText();
String e = txtMensual.getText();
e = e.replaceAll("[^\d.]","");
String f = txtfecha.getText();
String g = txtdeuda.getText();
g = g.replaceAll("[^\d.]","");
int c1 = Integer.parseInt(c);
long result = UUID.nameUUIDFromBytes((a+b).getBytes()).getMostSignificantBits();
String x = "" + result + "";
String sbStr = x.substring(0, 6);
sbStr = sbStr.replaceAll("[^\d.]","");
long csId = Long.parseLong(sbStr);
JOptionPane.showInternalMessageDialog(dskPane, "Cliente Ingresado con id#" + csId, "Cliente a Base de"
+ "Datos", 1, null);
connectMyDB con = new connectMyDB();
Statement state = null;

try
Connection charlie = con.connect();
state = charlie.createStatement();
String insert = "insert into APP.CLIENTES("+csId+",'"+a+"',"
+ "'"+b+"',"+c1+","+d+","+e+",'"+f+"',"+g+")";
state.executeUpdate(insert);
System.out.println(insert);
if(state!=null)
state.close();
charlie.close();

catch(SQLException ex)
System.out.print(ex);



I always get sql.SQLSyntaxErrorException: Syntax error: Encountered "61297" at line 1, column 26. Is there a way to avoid that?










share|improve this question















marked as duplicate by Basil Bourque java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 7 at 4:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Can you please do a System.out.println( insert ); just after you initialize insert and post the output here?

    – mypetlion
    Mar 6 at 19:50











  • I made the the System.out.print , the outcome is/////insert into APP.CLIENTES(406430,'AName ',' ALastaname',60, 5,1342.09,' 2019-10-10',80525.50)

    – Nemesis
    Mar 6 at 20:39












  • And then did you get "sql.SQLSyntaxErrorException: Syntax error: Encountered "406430" at line 1, column 26"?

    – Meg
    Mar 6 at 21:42











  • Always search Stack Overflow thoroughly before posting. Using UUID data type with JDBC has been covered many times already.

    – Basil Bourque
    Mar 7 at 4:28











  • Generally better to be using a prepared statement with placeholders that manipulating strings into SQL.

    – Basil Bourque
    Mar 7 at 4:30















0
















This question already has an answer here:



  • Postgres UUID JDBC not working

    4 answers



I have been trying to insert data from an app to a database, but always get a syntax error relating to a UUID number that will be the customer's ID, and primary key for the table. The column is set as BIGINT, it always returns. Here is the code:



String a = txtNombre.getText();
String b = txtApellido.getText();
String c = txtLetras.getText();
String d = txtFin.getText();
String e = txtMensual.getText();
e = e.replaceAll("[^\d.]","");
String f = txtfecha.getText();
String g = txtdeuda.getText();
g = g.replaceAll("[^\d.]","");
int c1 = Integer.parseInt(c);
long result = UUID.nameUUIDFromBytes((a+b).getBytes()).getMostSignificantBits();
String x = "" + result + "";
String sbStr = x.substring(0, 6);
sbStr = sbStr.replaceAll("[^\d.]","");
long csId = Long.parseLong(sbStr);
JOptionPane.showInternalMessageDialog(dskPane, "Cliente Ingresado con id#" + csId, "Cliente a Base de"
+ "Datos", 1, null);
connectMyDB con = new connectMyDB();
Statement state = null;

try
Connection charlie = con.connect();
state = charlie.createStatement();
String insert = "insert into APP.CLIENTES("+csId+",'"+a+"',"
+ "'"+b+"',"+c1+","+d+","+e+",'"+f+"',"+g+")";
state.executeUpdate(insert);
System.out.println(insert);
if(state!=null)
state.close();
charlie.close();

catch(SQLException ex)
System.out.print(ex);



I always get sql.SQLSyntaxErrorException: Syntax error: Encountered "61297" at line 1, column 26. Is there a way to avoid that?










share|improve this question















marked as duplicate by Basil Bourque java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 7 at 4:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Can you please do a System.out.println( insert ); just after you initialize insert and post the output here?

    – mypetlion
    Mar 6 at 19:50











  • I made the the System.out.print , the outcome is/////insert into APP.CLIENTES(406430,'AName ',' ALastaname',60, 5,1342.09,' 2019-10-10',80525.50)

    – Nemesis
    Mar 6 at 20:39












  • And then did you get "sql.SQLSyntaxErrorException: Syntax error: Encountered "406430" at line 1, column 26"?

    – Meg
    Mar 6 at 21:42











  • Always search Stack Overflow thoroughly before posting. Using UUID data type with JDBC has been covered many times already.

    – Basil Bourque
    Mar 7 at 4:28











  • Generally better to be using a prepared statement with placeholders that manipulating strings into SQL.

    – Basil Bourque
    Mar 7 at 4:30













0












0








0









This question already has an answer here:



  • Postgres UUID JDBC not working

    4 answers



I have been trying to insert data from an app to a database, but always get a syntax error relating to a UUID number that will be the customer's ID, and primary key for the table. The column is set as BIGINT, it always returns. Here is the code:



String a = txtNombre.getText();
String b = txtApellido.getText();
String c = txtLetras.getText();
String d = txtFin.getText();
String e = txtMensual.getText();
e = e.replaceAll("[^\d.]","");
String f = txtfecha.getText();
String g = txtdeuda.getText();
g = g.replaceAll("[^\d.]","");
int c1 = Integer.parseInt(c);
long result = UUID.nameUUIDFromBytes((a+b).getBytes()).getMostSignificantBits();
String x = "" + result + "";
String sbStr = x.substring(0, 6);
sbStr = sbStr.replaceAll("[^\d.]","");
long csId = Long.parseLong(sbStr);
JOptionPane.showInternalMessageDialog(dskPane, "Cliente Ingresado con id#" + csId, "Cliente a Base de"
+ "Datos", 1, null);
connectMyDB con = new connectMyDB();
Statement state = null;

try
Connection charlie = con.connect();
state = charlie.createStatement();
String insert = "insert into APP.CLIENTES("+csId+",'"+a+"',"
+ "'"+b+"',"+c1+","+d+","+e+",'"+f+"',"+g+")";
state.executeUpdate(insert);
System.out.println(insert);
if(state!=null)
state.close();
charlie.close();

catch(SQLException ex)
System.out.print(ex);



I always get sql.SQLSyntaxErrorException: Syntax error: Encountered "61297" at line 1, column 26. Is there a way to avoid that?










share|improve this question

















This question already has an answer here:



  • Postgres UUID JDBC not working

    4 answers



I have been trying to insert data from an app to a database, but always get a syntax error relating to a UUID number that will be the customer's ID, and primary key for the table. The column is set as BIGINT, it always returns. Here is the code:



String a = txtNombre.getText();
String b = txtApellido.getText();
String c = txtLetras.getText();
String d = txtFin.getText();
String e = txtMensual.getText();
e = e.replaceAll("[^\d.]","");
String f = txtfecha.getText();
String g = txtdeuda.getText();
g = g.replaceAll("[^\d.]","");
int c1 = Integer.parseInt(c);
long result = UUID.nameUUIDFromBytes((a+b).getBytes()).getMostSignificantBits();
String x = "" + result + "";
String sbStr = x.substring(0, 6);
sbStr = sbStr.replaceAll("[^\d.]","");
long csId = Long.parseLong(sbStr);
JOptionPane.showInternalMessageDialog(dskPane, "Cliente Ingresado con id#" + csId, "Cliente a Base de"
+ "Datos", 1, null);
connectMyDB con = new connectMyDB();
Statement state = null;

try
Connection charlie = con.connect();
state = charlie.createStatement();
String insert = "insert into APP.CLIENTES("+csId+",'"+a+"',"
+ "'"+b+"',"+c1+","+d+","+e+",'"+f+"',"+g+")";
state.executeUpdate(insert);
System.out.println(insert);
if(state!=null)
state.close();
charlie.close();

catch(SQLException ex)
System.out.print(ex);



I always get sql.SQLSyntaxErrorException: Syntax error: Encountered "61297" at line 1, column 26. Is there a way to avoid that?





This question already has an answer here:



  • Postgres UUID JDBC not working

    4 answers







java jdbc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 2:05









skomisa

6,60232047




6,60232047










asked Mar 6 at 18:53









NemesisNemesis

33




33




marked as duplicate by Basil Bourque java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 7 at 4:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Basil Bourque java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 7 at 4:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Can you please do a System.out.println( insert ); just after you initialize insert and post the output here?

    – mypetlion
    Mar 6 at 19:50











  • I made the the System.out.print , the outcome is/////insert into APP.CLIENTES(406430,'AName ',' ALastaname',60, 5,1342.09,' 2019-10-10',80525.50)

    – Nemesis
    Mar 6 at 20:39












  • And then did you get "sql.SQLSyntaxErrorException: Syntax error: Encountered "406430" at line 1, column 26"?

    – Meg
    Mar 6 at 21:42











  • Always search Stack Overflow thoroughly before posting. Using UUID data type with JDBC has been covered many times already.

    – Basil Bourque
    Mar 7 at 4:28











  • Generally better to be using a prepared statement with placeholders that manipulating strings into SQL.

    – Basil Bourque
    Mar 7 at 4:30

















  • Can you please do a System.out.println( insert ); just after you initialize insert and post the output here?

    – mypetlion
    Mar 6 at 19:50











  • I made the the System.out.print , the outcome is/////insert into APP.CLIENTES(406430,'AName ',' ALastaname',60, 5,1342.09,' 2019-10-10',80525.50)

    – Nemesis
    Mar 6 at 20:39












  • And then did you get "sql.SQLSyntaxErrorException: Syntax error: Encountered "406430" at line 1, column 26"?

    – Meg
    Mar 6 at 21:42











  • Always search Stack Overflow thoroughly before posting. Using UUID data type with JDBC has been covered many times already.

    – Basil Bourque
    Mar 7 at 4:28











  • Generally better to be using a prepared statement with placeholders that manipulating strings into SQL.

    – Basil Bourque
    Mar 7 at 4:30
















Can you please do a System.out.println( insert ); just after you initialize insert and post the output here?

– mypetlion
Mar 6 at 19:50





Can you please do a System.out.println( insert ); just after you initialize insert and post the output here?

– mypetlion
Mar 6 at 19:50













I made the the System.out.print , the outcome is/////insert into APP.CLIENTES(406430,'AName ',' ALastaname',60, 5,1342.09,' 2019-10-10',80525.50)

– Nemesis
Mar 6 at 20:39






I made the the System.out.print , the outcome is/////insert into APP.CLIENTES(406430,'AName ',' ALastaname',60, 5,1342.09,' 2019-10-10',80525.50)

– Nemesis
Mar 6 at 20:39














And then did you get "sql.SQLSyntaxErrorException: Syntax error: Encountered "406430" at line 1, column 26"?

– Meg
Mar 6 at 21:42





And then did you get "sql.SQLSyntaxErrorException: Syntax error: Encountered "406430" at line 1, column 26"?

– Meg
Mar 6 at 21:42













Always search Stack Overflow thoroughly before posting. Using UUID data type with JDBC has been covered many times already.

– Basil Bourque
Mar 7 at 4:28





Always search Stack Overflow thoroughly before posting. Using UUID data type with JDBC has been covered many times already.

– Basil Bourque
Mar 7 at 4:28













Generally better to be using a prepared statement with placeholders that manipulating strings into SQL.

– Basil Bourque
Mar 7 at 4:30





Generally better to be using a prepared statement with placeholders that manipulating strings into SQL.

– Basil Bourque
Mar 7 at 4:30












2 Answers
2






active

oldest

votes


















0














It is likely that the problem is that your csId, as a Long, is not represented internally in a way that makes it compatible with sql's bigInt. Even though they both stand for 'a really large integer', they are not the same thing 'under the hood'.



The usual solution is to keep the uuid as a string in your javascript, and it should be able to be inserted into a bigint field without issues as long as it contains only digits and the size is correct.






share|improve this answer























  • Thanks for the reply, I tried to change from long in to a string but is Still the same issue

    – Nemesis
    Mar 6 at 20:44


















1














One of the correct way for insert SQL command is:
insert into tables values (val1, val2, ...)



Also you have to use PreparedStatement to prevent SQL injections.






share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It is likely that the problem is that your csId, as a Long, is not represented internally in a way that makes it compatible with sql's bigInt. Even though they both stand for 'a really large integer', they are not the same thing 'under the hood'.



    The usual solution is to keep the uuid as a string in your javascript, and it should be able to be inserted into a bigint field without issues as long as it contains only digits and the size is correct.






    share|improve this answer























    • Thanks for the reply, I tried to change from long in to a string but is Still the same issue

      – Nemesis
      Mar 6 at 20:44















    0














    It is likely that the problem is that your csId, as a Long, is not represented internally in a way that makes it compatible with sql's bigInt. Even though they both stand for 'a really large integer', they are not the same thing 'under the hood'.



    The usual solution is to keep the uuid as a string in your javascript, and it should be able to be inserted into a bigint field without issues as long as it contains only digits and the size is correct.






    share|improve this answer























    • Thanks for the reply, I tried to change from long in to a string but is Still the same issue

      – Nemesis
      Mar 6 at 20:44













    0












    0








    0







    It is likely that the problem is that your csId, as a Long, is not represented internally in a way that makes it compatible with sql's bigInt. Even though they both stand for 'a really large integer', they are not the same thing 'under the hood'.



    The usual solution is to keep the uuid as a string in your javascript, and it should be able to be inserted into a bigint field without issues as long as it contains only digits and the size is correct.






    share|improve this answer













    It is likely that the problem is that your csId, as a Long, is not represented internally in a way that makes it compatible with sql's bigInt. Even though they both stand for 'a really large integer', they are not the same thing 'under the hood'.



    The usual solution is to keep the uuid as a string in your javascript, and it should be able to be inserted into a bigint field without issues as long as it contains only digits and the size is correct.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 6 at 19:06









    MegMeg

    218112




    218112












    • Thanks for the reply, I tried to change from long in to a string but is Still the same issue

      – Nemesis
      Mar 6 at 20:44

















    • Thanks for the reply, I tried to change from long in to a string but is Still the same issue

      – Nemesis
      Mar 6 at 20:44
















    Thanks for the reply, I tried to change from long in to a string but is Still the same issue

    – Nemesis
    Mar 6 at 20:44





    Thanks for the reply, I tried to change from long in to a string but is Still the same issue

    – Nemesis
    Mar 6 at 20:44













    1














    One of the correct way for insert SQL command is:
    insert into tables values (val1, val2, ...)



    Also you have to use PreparedStatement to prevent SQL injections.






    share|improve this answer



























      1














      One of the correct way for insert SQL command is:
      insert into tables values (val1, val2, ...)



      Also you have to use PreparedStatement to prevent SQL injections.






      share|improve this answer

























        1












        1








        1







        One of the correct way for insert SQL command is:
        insert into tables values (val1, val2, ...)



        Also you have to use PreparedStatement to prevent SQL injections.






        share|improve this answer













        One of the correct way for insert SQL command is:
        insert into tables values (val1, val2, ...)



        Also you have to use PreparedStatement to prevent SQL injections.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 2:21









        AlexAlex

        9,85152847




        9,85152847













            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved