I'm creating a method that will accept some values from a user and send them to a stored procedure in SQL server.Couple days ago the code was working fine now I'm getting these error that I don't know how to handle.This came up after I run the code 'java.lang.ClassNotFoundException' when I click on at java.lang.Class.forName0(Native Method) it states that the source attachment doesn't contain the source for Class.class and finally the other error I see takes me back to a line in the code
void addcustomer(int trn,String Lname,String Fname,String Mname,String Mstatus, String Dob,String Email,String tel,String PA,String MA,String Eng_num, int Emp_id,String dateP,String PartO)
{
String ConnectionUrl = "jdbc:sqlserver://localhost:1433;"+"databaseName=car_inventory;integratedSecurity=true;"; //creating a connection string
// Declare the JDBC objects
Connection Conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
//establish connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Conn=DriverManager.getConnection("jdbc:odbc:dbase2");/*This is the line where the last error points to*/
CallableStatement sp = Conn.prepareCall("{call addcustomer(?,?,?,?,?,?,?,?,?,?,?,?,?)}");
sp.setInt(1,trn);
sp.setString(2,Lname);
sp.setString(3,Fname);
sp.setString(4,Mname);
sp.setString(5,Mstatus);
sp.setString(6,Dob);
sp.setString(7,Email);
sp.setString(8,tel);
sp.setString(9,PA);
sp.setString(10,MA);
sp.setString(11,Eng_num);
sp.setInt(12,Emp_id);
sp.setString(13,dateP);
sp.setString(14,PartO);
}//end of try
catch(Exception e)
{
e.printStackTrace();
}//end of catch
finally
{
if (rs != null)
try
{
rs.close();
}
catch(Exception e)
{
}
if (stmt != null)
try
{
stmt.close();
}
catch(Exception e)
{
}
if (Conn != null)
try
{
Conn.close();
}
catch(Exception e)
{
}
}//end of finally
}//end of addcustomer
很可能您的类路径中没有驱动程序,请检查一下?
当JVM尝试加载一个类并且该类在类路径中不可用时,抛出ClassNotFoundException
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.