DATABASE



Database concepts : issues and solutions Error 2003: Can’t connect to MySQL server on ‘local host’ (10061)

Error 2003: Can’t connect to MySQL server on ‘local host’ (10061)

MySQL error message image
Can't connect to MySQL

  1. Uninstall mysql from your system
  2. Delete mysql folder from c:\program files
  3. Delete mysql folder from C:\Documents and Settings\All Users\Application Data for xp
  4. For windows 7 C:ProgramData
  5. Reinstall mysql
  6. While reinstalling there will be an option for remove instance in the mysql click on it

BLOB/TEXT column 'address' used in key specification without a key length


how to establish a connection to mysql using third party api in java 

 

java db connectivity
Establish connection in Database

 




import java.sql.*;

import java.sql.DriverManager;

public class Connector {
public static Connection connections()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/dbName","root","admin");
return con;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}


}


insertion, delete, update mysql query example using prepared statement


import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;

import javax.swing.JOptionPane;

public class Ipdao
{
String splits[]=null;



public void insert(Ipmanage ipmanage) throws SQLException
{

IPmanageUI i=new IPmanageUI();
Date date=new Date(new java.util.Date().getTime());
String ipadd=ipmanage.getIpadd();

int port=ipmanage.getPortno();


Connection con=Connector.connections();
PreparedStatement p= con.prepareStatement(" insert into ipmanagetable(ipadd,port,date) values(?,?,?)");
p.setString(1,ipadd);
p.setInt(2,port);
p.setDate(3, date);
p.executeUpdate();
System.out.println(" inserted ");

JOptionPane.showMessageDialog(i," inserted");
}

public void delete(Ipmanage ipmanage) throws SQLException

{
String ipadd=ipmanage.getIpadd();

Connection con=Connector.connections();

PreparedStatement p= con.prepareStatement(" delete from ipmanagetable where ipadd=?");
p.setString(1,ipadd);
p.executeUpdate();
IPmanageUI i=new IPmanageUI();
JOptionPane.showMessageDialog(i," Deleted");


}
public void edit(Ipmanage ipmanage)
{
String ipadd=ipmanage.getIpadd();
int port=ipmanage.getPortno();
Date date=new Date(new java.util.Date().getTime());
Connection con=Connector.connections();

PreparedStatement p;
try {
p = con.prepareStatement(" update ipmanagetable(ipadd,port,date) set value(?,?,?) where ipadd=?");
p.setString(1,ipadd);
p.setInt(2,port);
p.setDate(3,date);

IPmanageUI i=new IPmanageUI();
JOptionPane.showMessageDialog(i," Edited");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

public ArrayList SearchIp(Ipmanage ipmanage)
{
//String ipadd=ipmanage.getIpadd();
ArrayList arraylist=new ArrayList();
String ipad=ipmanage.getIpadd();

Connection con=Connector.connections();
PreparedStatement p;
try {
p = con.prepareStatement("Select * from ipmanagetable where ipadd=?" );
p.setString(1, ipad);
ResultSet rs =p.executeQuery();
while(rs.next())
{
Ipmanage im=new Ipmanage();
//im.setSerialno(rs.getInt(1));

im.setIpadd(rs.getString(1));
System.out.println("found");

im.setPortno(rs.getInt(2));
im.setDate(rs.getDate(3));
im.setTime(rs.getTimestamp(4));
arraylist.add(im);

}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(" no result");
MainFrame i=new MainFrame();
JOptionPane.showMessageDialog(i," No result found");
}

return arraylist;
}
public ArrayList Viewall()
{
//String ipadd=ipmanage.getIpadd();
ArrayList arraylist=new ArrayList();

Connection con=Connector.connections();
PreparedStatement p;
try {
p = con.prepareStatement("Select * from ipmanagetable" );
ResultSet rs =p.executeQuery();
while(rs.next())
{
Ipmanage im=new Ipmanage();
//im.setSerialno(rs.getInt(1));

im.setIpadd(rs.getString(1));

im.setPortno(rs.getInt(2));
im.setDate(rs.getDate(3));
im.setTime(rs.getTimestamp(4));
arraylist.add(im);}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return arraylist;
}
}



How google make data fetching faster ?

read more





Facebook comments