• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

connect my MySQl databse

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,
please you help me, i want to connect a jsp with the mysql databse
how do i go about doing that.

please help.
nhlanhla
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Server Pages have nothing to do with mysql. You can google for 'jdbc mysql' and you'll find a lot of quick starter tutorials about how to get and use mysql connection from java code.

You can then use the same method to obtain data in your servlet.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MySQL handbook section. Look for the link about connector/J. Probably worth running some basic SQL from the command-line interface to confirm MySQL is running correctly first.
Java™ Tutorials section.
 
nhlanhla mazibuko
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This my jsp page, that i want connect it with the database.
this is a code.
help me.

<%
Connection conn = null;
ResultSet result = null;
Statement stt = null;

try {
Class c = Class.forName("sun.jdbc.knotiondb.JdbcOdbcDriver");
}
catch (Exception e) {
System.out.println("Error occurred " + e);
}
try {
conn = DriverManager.getConnection("knotiondbc:mysql://locahost:3306/knotiondb","nhla123","nhlapass");
}
catch (SQLException e) {
System.out.println("Error found " + e);
}
try {
stt = conn.createStatement();
result = stt.executeQuery("MySQL Query * localhost:3306/knotionbd");
}
catch (SQLException e) {
System.out.println("Error occurred " + e);
}
%>
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that it's not a good practice to mix Java/JDBC code and JSP. The JDBC should be in a servlet (or class called from a servlet) and then forward to a JSP. It is harder to develop, troubleshoot, maintain and reuse code in a JSP. Which wil negatively impact getting it working.

In any case, what error do you get when you try to run your code?

Also, you should only have one try/catch. If an exception is caught, it doesn't make sense to continue.
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@nhlanhla mazibuko
Is there any any specific reason for which you are not using JDBC Driver for MySQL. Here's a sample code below for connecting to MySQL using mysql Connector/J:


 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic