java - Connection Manage File Throw Exception. please provide solution .thanks -
code-1 : (working fine)
package com.connection; import java.sql.*; public class sqlserverjdbc { public static void main(string[] args) { try { string server,user,password,database; int port; string jdbcurl; server="admin-pc"; port =1433; user="sa"; password="admin@123"; database="ordd_login_db"; class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); system.out.println("#- driver load"); jdbcurl="jdbc:sqlserver://"+server+":"+port+";user="+user+";password="+password+";databasename="+database+";"; system.out.println("constring="+jdbcurl); connection con=drivermanager.getconnection(jdbcurl); system.out.println("# - connection obtained"); statement stmt=con.createstatement(); system.out.println("# - statment obtained"); resultset rs=stmt.executequery("select * userinfo;"); system.out.println("# - query executed"); if (rs.next()) { system.out.println("output colume = "+rs.getstring(1)); } rs.close();stmt.close();con.close(); system.out.println("resource relised......done"); }catch(exception e) { system.out.print(e); } } }
code-2 (not working)
package com.connection; import java.sql.*; public class sqlserverjdbc { public static connection getconnection() { connection con = null; try { string server,user,password,database,jdbcurl; int port; server="admin-pc";port =1433;user="sa";password="admin@123";database="ordd_login_db"; class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); system.out.println("#- driver load"); jdbcurl="jdbc:sqlserver://"+server+":"+port+";user="+user+";password="+password+";databasename="+database+";"; system.out.println("constring="+jdbcurl); con=drivermanager.getconnection(jdbcurl); system.out.println("# - connection obtained"); }catch(exception e) { system.out.print(e); } system.out.println(con); return con; } }
error massage:
java.lang.classnotfoundexception: com.microsoft.sqlserver.jdbc.sqlserverdriver null java.lang.nullpointerexception
Comments
Post a Comment