I am able to ping database successflly and able to see created table results successfully. When I try to insert from java program getting errorss as below after commenting below lines
      psmt.setPersonid(1,111);
      psmt.setfirstname(2,"sss");
      psmt.setage(3,333);
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/MySql
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at DBConnect.main(DBConnect.java:19)
I do have mysql jdbc jar in the build path.
i also see when i comment below lines
      psmt.setPersonid(1,111);
      psmt.setfirstname(2,"sss");
      psmt.setage(3,333);
getting errors
The method setPersonid(int, int) is undefined for the type PreparedStatement
I also see messages like add cast to psmt etc.
I see two import options for PreparedStatement one from SQL other from SQL.jdbc package. what are the difference between those two.
I am getting error there like
Type mismatch: cannot convert from java.sql.PreparedStatement to com.mysql.jdbc.PreparedStatement
 Which one should i select.
Please advise. Any ideas, resources, sample code highly appreciated. thanks in advance
i modified the code as below
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//import java.sql.PreparedStatement;
import java.sql.SQLException;
//import com.mysql.PreparedStatement;
//import com.sql.PreparedStatement;
public class DBConnect {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/MySql","root","root");
String queryy="insert into xyz_table values(?,?,?)";
System.out.println("queryy is"+queryy);
PreparedStatement psmt=conn.prepareStatement(queryy);
//psmt.setp
//psmt.setPersonid(1,111);
psmt.setInt(1,111);
psmt.setString(2,"sss");
//psmt.setfirstname(2,"sss");
psmt.setDouble(3,333);
//psmt.setage(3,333);
psmt.executeUpdate();
System.out.println("connected");
System.out.println("inserted well");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
i still get error as below
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/MySql
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at DBConnect.main(DBConnect.java:20)
I am using Eclipse Juno version. I am attaching the screenshot. When queries with select statement it says empty set as the table is empty. please advise EmptySet.jpg
      /**
      * @param args
      */
      public static void main(String[] args) {
           // TODO Auto-generated method stub
try {
      Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/MySql","root","root");
String queryy="select * from users";
//System.out.println("queryy is"+queryy);
     Â
      PreparedStatement psmt=conn.prepareStatement(queryy);
                 //psmt.setp
      //psmt.setPersonid(1,111);
      ResultSet rs=psmt.executeQuery();
      int count=0;
      while(rs.next()){
          Â
          Â
           System.out.println(rs.getInt(1));
           System.out.println(rs.getString(2));
           System.out.println(rs.getString(3));
           System.out.println(rs.getDate(4));
           System.out.println(rs.getBoolean(5));
           System.out.println(rs.getInt(6));
           //System.out.println(rs.getInt(6));
      }
      System.out.println("connected");
      //System.out.println("inserted well");
     Â
} catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
}
      }
     Â
}
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/MySql
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at DBRetrieve.main(DBRetrieve.java:21)
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.