Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

unreported Exception java.lang.InstantiationException

843859Aug 24 2008 — edited Aug 24 2008
Dear Friends,

I am developing javabean connectivty for inserting records to mysql database from jsp. when i try to compile java bean program. It gives an error like unreported Exception java.lang.InstantiationException: Must be caught or declared to be thrown*. This is my mode. Please anyone help to solve this error. if you find any error in my code, please suggest me. Thanks in advance.

package com.webdeveloper.servlets;

import java.sql.*;
import java.io.*;

public class InsertBean {

private String dbURL = "jdbc:mysql://localhost:3306/test";
private Connection dbCon;
private Statement st;
String dbuser = "root";
String dbpass = "admin";

String Name = null;
String Address = null;
String Zip = null;

public InsertBean() {
super();
}

public String getName() {
return this.Name;
}

public String getAddress() {
return this.Address;
}

public String getZip() {
return this.Zip;
}

public void setName(String pname) {
this.Name = pname;
}

public void setAddress(String paddress) {
this.Address = paddress;
}

public void setZip(String pzip) {
this.Zip = pzip;
}


public void doInsert() throws ClassNotFoundException, SQLException {

Class.forName("com.mysql.jdbc.Driver").newInstance();//it gives error in this line
dbCon = DriverManager.getConnection(dbURL,dbuser,dbpass);
Statement s = dbCon.createStatement();
String sql = "Insert into Person values ('" + this.Name;
sql = sql + "', '" + this.Address + "', " + this.Zip;
sql = sql + ")";
int insertResult = s.executeUpdate(sql);
dbCon.close();
}



}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2008
Added on Aug 24 2008
5 comments
673 views