• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JBoss & MySQL

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using
JBoss4.0.1 server
MySQL 4.0.23 database
& MySQL connector/J 3.1.6 driver
for an application. Here in a JSP file I've used the following code fragment:
------------------------------------------------------------
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();

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

Statement stmt = con.createStatement();

boolean exRes = stmt.execute("CREATE TABLE Phonebook (name VARCHAR(60),phoneNumber VARCHAR(15))");

out.println("Table Created");
}
catch(Exception e)
{
out.println("SORRY For the error");
}
%>
-------------------------------------------------------------
though the table is not created it is giving the output:
SORRY For the error
-------------------------------------------------------------
But the same jdbc connection working fine from a simple .java file...
Is there any anything else required for jdbc connection?

please help.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A few things:
  • Its very bad style to include JDBC code in your JSP. In fact its usually considered poor design is you have anything more than simple View code in a JSP. Consider the DAO pattern.
  • Have a close look at that JDBC connection URL - and reread the Connector/J documentation. You should spot the problem.
  • Handle your exceptions better. You catch an Exception then do nothing to log why it was thrown. What's wrong with logging the stack trace?

  •  
    Siddhartha Mukherjee
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    1.just copy the mysql-ds.xml from JBOSS_HOME/docs/exampls/jca/ to JBOSS_HOME/Server/default/deploy.

    2.copy the driver .jar file in JBOSS_HOME/server/default/lib/ .

    3.make the necessary changes in the mysql-ds.xml file
    ------------------------------------------------------
    Then it will work
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    ...well it might, if he were using a DataSource. Which he is not.
     
    If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic