Getting SQL server exception when executing connection java file through ant build.xml file -
- i have java file connect sql server database , retrieve data it.
- when execute java file eclipse connects database , retrieve data db.
- but when call same java file ant build.xml file, throwing sql server exception while creating connection object.
not able may issue. please help!!
sql exception thrown: -
com.microsoft.sqlserver.jdbc.sqlserverexception: tcp/ip connection host 10.6.1.67, port 1433 has failed. error: "null. verify connection properties, check instance of sql server running on host , accepting tcp/ip connections @ port, , no firewall blocking tcp connections port.". [java] @ org.apache.tools.ant.taskdefs.executejava.execute(executejava.java:194) [java] @ org.apache.tools.ant.taskdefs.java.run(java.java:771) [java] @ org.apache.tools.ant.taskdefs.java.executejava(java.java:221) [java] @ org.apache.tools.ant.taskdefs.java.executejava(java.java:135) [java] @ org.apache.tools.ant.taskdefs.java.execute(java.java:108) [java] @ org.apache.tools.ant.unknownelement.execute(unknownelement.java:292) [java] @ sun.reflect.generatedmethodaccessor4.invoke(unknown source) [java] @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) [java] @ java.lang.reflect.method.invoke(unknown source) [java] @ org.apache.tools.ant.dispatch.dispatchutils.execute(dispatchutils.java:106) [java] @ org.apache.tools.ant.task.perform(task.java:348) [java] @ org.apache.tools.ant.target.execute(target.java:435) [java] @ org.apache.tools.ant.target.performtasks(target.java:456) [java] @ org.apache.tools.ant.project.executesortedtargets(project.java:1393) [java] @ org.apache.tools.ant.project.executetarget(project.java:1364) [java] @ org.apache.tools.ant.helper.defaultexecutor.executetargets(defaultexecutor.java:41) [java] @ org.eclipse.ant.internal.launching.remote.eclipsedefaultexecutor.executetargets(eclipsedefaultexecutor.java:36) [java] @ org.apache.tools.ant.project.executetargets(project.java:1248) [java] @ org.eclipse.ant.internal.launching.remote.internalantrunner.run(internalantrunner.java:452) [java] @ org.eclipse.ant.internal.launching.remote.internalantrunner.main(internalantrunner.java:139)
below java file code:-
package util; import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; public class javasqlconnection{ public static void main(string[] args) throws exception { string connectionurl="jdbc:sqlserver://10.6.1.67"; string port="1433"; string databasename="microsoft"; string user="selenium"; string password="password123"; class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver").newinstance(); connection conn = drivermanager.getconnection(connectionurl+":"+port+";databasename="+databasename+";user="+user+";password="+password); string sql = "select name, address, url school schoolid=?"; preparedstatement stmt = conn.preparestatement(sql); resultset rs = null; stmt.setint(1, 875632); rs = stmt.executequery(); while (rs.next()){ system.out.println(rs.getstring("url")); } stmt.close(); conn.close(); } }
this how have created ant build.xml:(i execute ant target run)
<?xml version="1.0" encoding="iso-8859-1"?> <!doctype project [ ]> <project name="sample" basedir="."> <property environment="env" /> <property name="proj.home" value="${basedir}" /> <property name="lib.location" value="${proj.home}/lib" /> <property name="build.location" value="${proj.home}/build" /> <property name="classes.location" value="${build.location}\compiledclasses" /> <property name="src.location" value="${proj.home}/src" /> <path id="classpath"> <fileset dir="${lib.location}"> <include name="*.jar" /> </fileset> </path> <target name="clean"> <delete failonerror="false" dir="${build.location}" /> </target> <!-- compile --> <target name="compile" depends="clean"> <mkdir dir="${build.location}" /> <mkdir dir="${classes.location}" /> <javac includeantruntime="true" srcdir="${src.location}" destdir="${classes.location}" classpathref="classpath" /> </target> <!-- run --> <target name="run" depends="compile"> <java classname="util.javasqlconnection" classpath="${classes.location}" classpathref="classpath" /> </target> </project>
Comments
Post a Comment