SQL statement is not executedcom.mysql.jdbc.CommunicationsException: Communications link >failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException MESSAGE: Connection refused
STACKTRACE:
java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384) at java.net.Socket.connect(Socket.java:546) at java.net.Socket.connect(Socket.java:495) at java.net.Socket.(Socket.java:392) at java.net.Socket.(Socket.java:235) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:271) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771) at com.mysql.jdbc.Connection.(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:620) at java.sql.DriverManager.getConnection(DriverManager.java:200) at org.jtdemo.preparedst.main(preparedst.java:18)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago. at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847) at com.mysql.jdbc.Connection.(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:620) at java.sql.DriverManager.getConnection(DriverManager.java:200) at org.jtdemo.preparedst.main(preparedst.java:18)
My program is
package org.jtdemo;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class preparedst
{
//private static final String y = null;
public static void main(String arg[])throws Exception
{
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3036/mylib_db";
Connection con=DriverManager.getConnection(url,"nikki","dkm007");
String query = " select c.sub_category, b.title,b.author,b.b_key,ta.available_copies" +
"from Book_dim b,Category_list c,item_availablity_fact ta" +
" where sub_category = 'Mathematics' and " +
" c.category_id=b.category_id and " +
" b.b_key=ta.b_key " ;
/*ps = con.prepareStatement(" select c.sub_category, b.title,b.author,b.b_key,ta.available_copies" +
"from Book_dim b,Category_list c,item_availablity_fact ta" +
" where sub_category = ? and " +
" c.category_id=b.category_id and " +
" b.b_key=ta.b_key ");*///pass sql query ,no parameter passing
//ps.String(1, "Mathematics"); // set input parameter
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query) ;
while(rs.next())
{
String scat = rs.getString(1);
String ttl = rs.getString(2);
String auth = rs.getString(3);
int bkey = rs.getInt(4);
int avcop = rs.getInt(5);
//String b_key;
System.out.println("subcategory:"+scat+"title:"+ttl+"author:"+auth+"bookkey:"+bkey+"availcopies:"+avcop);
}
con.close();
//ps.close();
}
catch(Exception e)
{
System.out.println("SQL statement is not executed");
e.printStackTrace();
}
}
}
i am using jdk 1.6,mysql-connector-java-5.0.8-bin.jar,Eclipse Version: 3.5.2.
Please help.................