2012-07-24 117 views
-1

JDBC空指针错误。同时访问数据库。这是我正在执行的查询。JDBC和MS-Access空指针

"INSERT INTO paritosh (customer, contactPerson, mobileNo, phoneNo, emailId, chairman, instituteName, totalEmployees, totalFaculty, totalStudents, totalClassroom, address, state, revenue, clientRate, acceptedRate, valuePerCard, rating, finderName, finderFee, comments) VALUES ('kinley', 'adfa' , '232131' , '2323' , '@gmail' , 'adfadf' , 'zxc' ,100,11,1000,30, 'dfdfa' , 'Delhi' , 66000,60000,60000,600, 'Hot' , 'tyu' , 8, 'dfadfadfasdf');" 

如果我执行的代码,查询中运行良好的访问SQL查询.....

请帮

的JDBC代码如下:

String insertq="INSERT INTO paritosh (customer, contactPerson, mobileNo, phoneNo, emailId, chairman, instituteName, totalEmployees, totalFaculty, totalStudents, totalClassroom, address, state, revenue, clientRate, acceptedRate, valuePerCard, rating, finderName, finderFee, comments)"; 

String query=" VALUES ('"+customer+"', '"+contact+"' , '"+mobile+"' , '"+phone+"' , '"+email+"' , '"+chairman+"' , '"+institute+"' ,"+totalEmployees+","+totalFaculty+","+totalStudents+","+classroom+", '"+address+"' , '"+state+"' , "+revenue+","+clientRate+","+accepRate+","+valPercard+", '"+Rating+"' , '"+finderName+"' , "+finderFee+", '"+comment+"');"; 
    String build=insertq+query; 

String query2="INSERT INTO paritosh (customer, contactPerson, mobileNo, phoneNo, emailId, chairman, instituteName, totalEmployees, totalFaculty, totalStudents, totalClassroom, address, state, revenue, clientRate, acceptedRate, valuePerCard, rating, finderName, finderFee, comments) VALUES ('virappan', 'dussal' , '4269887' , '12334567' , '[email protected]' , 'kumar' , 'RMIT' ,300,120,3000,150, 'adfad' , 'Delhi' , 400000,380000,390000,1500, 'Hot' , 'vineet' , 9, 'afddf');"; 

try{ 
    s.execute(build); 
} 
catch(SQLException se) 
{ 
    System.out.println("SQL eception"); 
} 
catch(Exception e) 
{ 
    System.out.println(e); 
    System.out.println(" error after running the query"); 
} 
+0

你能提供完整的堆栈跟踪吗?另外,你是否确定's'不是null? – Sujay 2012-07-24 15:11:04

回答

0
  • 看着你的代码,我建议你考虑使用PreparedStatement而不是你正在做的方式。

  • 确保在调用​​方法之前设置了连接。请注意,这仅基于您提供的内容。如果您希望我们查看您的整体代码并帮助您,请考虑发布SSCCE