• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Struts 2- Database Connectivity

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to connect my Access database but failed.
****I got the exception:

javax.servlet.ServletException
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:518)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter
(FilterDispatcher.java:421)

*** my code is


public String execute() throws Exception {
String url = "jdbc dbc:hsw";
String dbName = "harshani";
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "root";
String password = "root";
Connection con=null;
Statement stmt=null;
try{
Class.forName(driverName).newInstance();
con=DriverManager.getConnection(url+dbName, userName, password);
stmt=con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
String uname=getUsername();
String pws=getPassword();
stmt = con.createStatement();
int val = stmt.executeUpdate("INSERT employee VALUES('"+uname+"','"+pws+"')");
if(val == 0){
return ERROR;
}
else{
return SUCCESS;
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic