MySQL Connection to data base to java The 2019 Stack Overflow Developer Survey Results Are InIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Should I use the datetime or timestamp data type in MySQL?How do I convert a String to an int in Java?Creating a memory leak with JavaI tried connecting mysql database to java but i got the exception as “com.mysql.jdbc.Driver”

On the insanity of kings as an argument against monarchy

In microwave frequencies, do you use a circulator when you need a (near) perfect diode?

How to reverse every other sublist of a list?

How to deal with fear of taking dependencies

Should I use my personal or workplace e-mail when registering to external websites for work purpose?

JSON.serialize: is it possible to suppress null values of a map?

"To split hairs" vs "To be pedantic"

I looked up a future colleague on LinkedIn before I started a job. I told my colleague about it and he seemed surprised. Should I apologize?

How are circuits which use complex ICs normally simulated?

How was Skylab's orbit inclination chosen?

Extreme, unacceptable situation and I can't attend work tomorrow morning

What is this 4-propeller plane?

Realistic Alternatives to Dust: What Else Could Feed a Plankton Bloom?

Patience, young "Padovan"

Why is Grand Jury testimony secret?

Is bread bad for ducks?

Is this food a bread or a loaf?

Is there a name of the flying bionic bird?

What is the use of option -o in the useradd command?

Why is it "Tumoren" and not "Tumore"?

Dual Citizen. Exited the US on Italian passport recently

Spanish for "widget"

Are there any other methods to apply to solving simultaneous equations?

Inflated grade on resume at previous job, might former employer tell new employer?



MySQL Connection to data base to java



The 2019 Stack Overflow Developer Survey Results Are InIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Should I use the datetime or timestamp data type in MySQL?How do I convert a String to an int in Java?Creating a memory leak with JavaI tried connecting mysql database to java but i got the exception as “com.mysql.jdbc.Driver”



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I cannot connect to my MySQL database, and so I can't INSERT any data. How can I solve the problem?



Here is my code:



public void actionPerformed(ActionEvent arg0) 
try
Class.forName("com.mysql.jdbc.Driver");
String query = "INSERT INTO tbl_login (id, tfname, password) VALUES (NULL,'" + tf.getText() + "', '" + pf1.getText() + "')";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog", "root", null);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

java.sql.PreparedStatement = con.prepareStatement(query);
JOptionPane.showMessageDialog(null, "Connected to Database ");
rs.executeUpdate();

info1 tbl_login = new info1();
tbl_login.main(null);
frame.dispose();

catch (SQLException e)
JOptionPane.showMessageDialog(null, "Cannot find Database Name ");
catch (ClassNotFoundException et)
JOptionPane.showMessageDialog(null, "Cannot find MySQL Driver ");











share|improve this question



















  • 1





    What error are you getting?

    – Darshan Mehta
    Mar 19 at 9:44











  • no error but can't connect it to the database and no show of data in to the table thankyou sir! btw i use XAMPP

    – Jom L
    Mar 19 at 9:47











  • You are not setting the password while connecting. That might be why it's not able to connect.

    – Darshan Mehta
    Mar 19 at 9:49











  • use password instead of null

    – Onkar Musale
    Mar 19 at 9:51











  • sir darshan mehta can i add you to messenger/facebook to see the problem thankyou sir for helping me

    – Jom L
    Mar 19 at 9:51

















1















I cannot connect to my MySQL database, and so I can't INSERT any data. How can I solve the problem?



Here is my code:



public void actionPerformed(ActionEvent arg0) 
try
Class.forName("com.mysql.jdbc.Driver");
String query = "INSERT INTO tbl_login (id, tfname, password) VALUES (NULL,'" + tf.getText() + "', '" + pf1.getText() + "')";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog", "root", null);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

java.sql.PreparedStatement = con.prepareStatement(query);
JOptionPane.showMessageDialog(null, "Connected to Database ");
rs.executeUpdate();

info1 tbl_login = new info1();
tbl_login.main(null);
frame.dispose();

catch (SQLException e)
JOptionPane.showMessageDialog(null, "Cannot find Database Name ");
catch (ClassNotFoundException et)
JOptionPane.showMessageDialog(null, "Cannot find MySQL Driver ");











share|improve this question



















  • 1





    What error are you getting?

    – Darshan Mehta
    Mar 19 at 9:44











  • no error but can't connect it to the database and no show of data in to the table thankyou sir! btw i use XAMPP

    – Jom L
    Mar 19 at 9:47











  • You are not setting the password while connecting. That might be why it's not able to connect.

    – Darshan Mehta
    Mar 19 at 9:49











  • use password instead of null

    – Onkar Musale
    Mar 19 at 9:51











  • sir darshan mehta can i add you to messenger/facebook to see the problem thankyou sir for helping me

    – Jom L
    Mar 19 at 9:51













1












1








1








I cannot connect to my MySQL database, and so I can't INSERT any data. How can I solve the problem?



Here is my code:



public void actionPerformed(ActionEvent arg0) 
try
Class.forName("com.mysql.jdbc.Driver");
String query = "INSERT INTO tbl_login (id, tfname, password) VALUES (NULL,'" + tf.getText() + "', '" + pf1.getText() + "')";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog", "root", null);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

java.sql.PreparedStatement = con.prepareStatement(query);
JOptionPane.showMessageDialog(null, "Connected to Database ");
rs.executeUpdate();

info1 tbl_login = new info1();
tbl_login.main(null);
frame.dispose();

catch (SQLException e)
JOptionPane.showMessageDialog(null, "Cannot find Database Name ");
catch (ClassNotFoundException et)
JOptionPane.showMessageDialog(null, "Cannot find MySQL Driver ");











share|improve this question
















I cannot connect to my MySQL database, and so I can't INSERT any data. How can I solve the problem?



Here is my code:



public void actionPerformed(ActionEvent arg0) 
try
Class.forName("com.mysql.jdbc.Driver");
String query = "INSERT INTO tbl_login (id, tfname, password) VALUES (NULL,'" + tf.getText() + "', '" + pf1.getText() + "')";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog", "root", null);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

java.sql.PreparedStatement = con.prepareStatement(query);
JOptionPane.showMessageDialog(null, "Connected to Database ");
rs.executeUpdate();

info1 tbl_login = new info1();
tbl_login.main(null);
frame.dispose();

catch (SQLException e)
JOptionPane.showMessageDialog(null, "Cannot find Database Name ");
catch (ClassNotFoundException et)
JOptionPane.showMessageDialog(null, "Cannot find MySQL Driver ");








java mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 2:48









kahveci

521315




521315










asked Mar 19 at 9:42









Jom LJom L

61




61







  • 1





    What error are you getting?

    – Darshan Mehta
    Mar 19 at 9:44











  • no error but can't connect it to the database and no show of data in to the table thankyou sir! btw i use XAMPP

    – Jom L
    Mar 19 at 9:47











  • You are not setting the password while connecting. That might be why it's not able to connect.

    – Darshan Mehta
    Mar 19 at 9:49











  • use password instead of null

    – Onkar Musale
    Mar 19 at 9:51











  • sir darshan mehta can i add you to messenger/facebook to see the problem thankyou sir for helping me

    – Jom L
    Mar 19 at 9:51












  • 1





    What error are you getting?

    – Darshan Mehta
    Mar 19 at 9:44











  • no error but can't connect it to the database and no show of data in to the table thankyou sir! btw i use XAMPP

    – Jom L
    Mar 19 at 9:47











  • You are not setting the password while connecting. That might be why it's not able to connect.

    – Darshan Mehta
    Mar 19 at 9:49











  • use password instead of null

    – Onkar Musale
    Mar 19 at 9:51











  • sir darshan mehta can i add you to messenger/facebook to see the problem thankyou sir for helping me

    – Jom L
    Mar 19 at 9:51







1




1





What error are you getting?

– Darshan Mehta
Mar 19 at 9:44





What error are you getting?

– Darshan Mehta
Mar 19 at 9:44













no error but can't connect it to the database and no show of data in to the table thankyou sir! btw i use XAMPP

– Jom L
Mar 19 at 9:47





no error but can't connect it to the database and no show of data in to the table thankyou sir! btw i use XAMPP

– Jom L
Mar 19 at 9:47













You are not setting the password while connecting. That might be why it's not able to connect.

– Darshan Mehta
Mar 19 at 9:49





You are not setting the password while connecting. That might be why it's not able to connect.

– Darshan Mehta
Mar 19 at 9:49













use password instead of null

– Onkar Musale
Mar 19 at 9:51





use password instead of null

– Onkar Musale
Mar 19 at 9:51













sir darshan mehta can i add you to messenger/facebook to see the problem thankyou sir for helping me

– Jom L
Mar 19 at 9:51





sir darshan mehta can i add you to messenger/facebook to see the problem thankyou sir for helping me

– Jom L
Mar 19 at 9:51












1 Answer
1






active

oldest

votes


















0














Use Empty String instead of null for password as:



Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog","root","");





share|improve this answer























  • sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

    – Jom L
    Mar 19 at 9:57












  • what is the error ?

    – Mustahsan
    Mar 19 at 9:58











  • at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

    – Jom L
    Mar 19 at 10:05











  • That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

    – NickJ
    Mar 19 at 10:11











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55237833%2fmysql-connection-to-data-base-to-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Use Empty String instead of null for password as:



Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog","root","");





share|improve this answer























  • sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

    – Jom L
    Mar 19 at 9:57












  • what is the error ?

    – Mustahsan
    Mar 19 at 9:58











  • at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

    – Jom L
    Mar 19 at 10:05











  • That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

    – NickJ
    Mar 19 at 10:11















0














Use Empty String instead of null for password as:



Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog","root","");





share|improve this answer























  • sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

    – Jom L
    Mar 19 at 9:57












  • what is the error ?

    – Mustahsan
    Mar 19 at 9:58











  • at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

    – Jom L
    Mar 19 at 10:05











  • That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

    – NickJ
    Mar 19 at 10:11













0












0








0







Use Empty String instead of null for password as:



Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog","root","");





share|improve this answer













Use Empty String instead of null for password as:



Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/prog","root","");






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 19 at 9:53









MustahsanMustahsan

624214




624214












  • sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

    – Jom L
    Mar 19 at 9:57












  • what is the error ?

    – Mustahsan
    Mar 19 at 9:58











  • at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

    – Jom L
    Mar 19 at 10:05











  • That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

    – NickJ
    Mar 19 at 10:11

















  • sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

    – Jom L
    Mar 19 at 9:57












  • what is the error ?

    – Mustahsan
    Mar 19 at 9:58











  • at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

    – Jom L
    Mar 19 at 10:05











  • That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

    – NickJ
    Mar 19 at 10:11
















sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

– Jom L
Mar 19 at 9:57






sir thankyou and i having error on this but still runnable //java.sql.PreparedStatement = con.prepareStatement(query); JOptionPane.showMessageDialog(null, "Connected to Database "); //rs.executeUpdate();

– Jom L
Mar 19 at 9:57














what is the error ?

– Mustahsan
Mar 19 at 9:58





what is the error ?

– Mustahsan
Mar 19 at 9:58













at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

– Jom L
Mar 19 at 10:05





at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) if i submit data

– Jom L
Mar 19 at 10:05













That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

– NickJ
Mar 19 at 10:11





That error does not look complete, I'd expect the top line to be in your class, and it also looks like the problem is with your UI, not the database connection.

– NickJ
Mar 19 at 10:11



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55237833%2fmysql-connection-to-data-base-to-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript