File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes JBoss & MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JBoss & MySQL" Watch "JBoss & MySQL" New topic

JBoss & MySQL

Siddhartha Mukherjee

Joined: Jan 27, 2005
Posts: 8
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:

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.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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?

  • JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    Siddhartha Mukherjee

    Joined: Jan 27, 2005
    Posts: 8
    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

    Joined: Apr 14, 2004
    Posts: 10336

    ...well it might, if he were using a DataSource. Which he is not.
    I agree. Here's the link:
    subject: JBoss & MySQL
    It's not a secret anymore!