| Author |
JBoss & MySQL
|
Siddhartha Mukherjee
Greenhorn
Joined: Jan 27, 2005
Posts: 8
|
|
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.
|
 |
Paul Sturrock
Bartender
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
Greenhorn
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
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
...well it might, if he were using a DataSource. Which he is not.
|
 |
 |
|
|
subject: JBoss & MySQL
|
|
|