Results 1 to 3 of 3
  1. #1
    nur
    nur is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default problem with sql connection

    dear friend. i got problem to connect java apps with sql database. this implementation made by using dk1.6,mysql xamp,jdbc.
    when run it,the error with message "not suitable driver found for jdbc. already tried to install the jdbc driver n set classpath, but not succeeded.im begging for help here . before that,thankyou and forgive my english

    this link,show my output : imgPlace.com - Image Hosting - Free Image Hosting - Free Image Uploading - image 6026

    here my code:


    import java.util.*;
    import java.io.*;
    import java.sql.*;
    import java.lang.*;

    public class function{

    public static String filename;
    public static Scanner input;
    public static String[] data;

    public void uploadSQL() {
    System.out.println("============================== =========");
    System.out.println("\tUpload to SQL :"+filename);
    System.out.println("============================== =========");

    try{

    //Connection conn = null;
    Statement stmt = null;
    //prepareStatement = null;
    ResultSet rs = null;

    //load JDBC Driver
    /* try{
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    System.out.println("Driver loaded");
    }
    catch (Exception ex) {
    }*/

    //Establish a connection
    String url = "jdbc:mysql://localhost/company?user=root&password=tiger";
    Connection conn = DriverManager.getConnection(url,"root","tiger");
    //conn =DriverManager.getConnection("jdbc:mysql://localhost/mydatabase?"+"userName=root&password=tiger");
    System.out.println("Database connected");

    //Create statement
    stmt = conn.createStatement();
    rs = stmt.executeQuery("INSERT INTO student(name,matric,gender,state,faculty)"+ "values(?,?,?,?,?)");

    try{
    FileReader fr = new FileReader(new File(filename));
    BufferedReader br = new BufferedReader(fr);
    String value;

    while((value = br.readLine()) != null){
    String[] column = value.split(",");
    for(int i = 0; i<column.length; i++){
    if(!column[i].trim().equals("")) {
    rs = stmt.executeQuery(column[i]);
    //System.out.println(">>"+column[i]);
    }
    }
    }
    br.close();
    }
    catch(IOException e){
    e.printStackTrace();
    System.out.println("File not found!");
    }
    System.out.println("successful insert data");
    System.out.println("All data are inserted in the database table");

    //Close the connection
    conn.close();
    }
    catch(SQLException ex){
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());
    //System.out.println("Not found");
    }
    }

    public void readFromFile(){

    try{
    System.out.println();
    System.out.println("============================== =======================");
    System.out.println("\tWELCOME TO JAVA APPLICATION");
    System.out.println("============================== =======================");
    System.out.println();
    System.out.print("Enter CSV file name:\t");
    //System.out.println();
    Scanner readkey = new Scanner(System.in);
    filename = readkey.next();

    //use buffering
    FileInputStream file = new FileInputStream(filename);
    DataInputStream data = new DataInputStream(file);
    BufferedReader input = new BufferedReader(new InputStreamReader(data));
    System.out.println("File Found!");
    data.close();
    file.close();
    input.close();
    }

    catch(IOException e){
    e.printStackTrace();
    System.out.println("File not found!");

    }

    }
    }

  2. #2
    clydedoris is offline Member
    Join Date
    Feb 2010
    Posts
    80
    Rep Power
    0

    Default Re: problem with sql connection

    the code is really painful for the eyes. try formatting it.
    [why are you annoyed with my sig?]

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default Re: problem with sql connection

    If you don't know how to format please have a look at my forum signature (or forum FAQ). I have added a link to that page there.

Similar Threads

  1. Connection problem
    By Levian in forum JDBC
    Replies: 4
    Last Post: 09-13-2011, 02:23 AM
  2. URL connection problem
    By rajeshgubba in forum New To Java
    Replies: 8
    Last Post: 04-23-2009, 06:22 PM
  3. Too many Connection Problem Plz Help
    By shuvra_pan in forum Advanced Java
    Replies: 3
    Last Post: 03-17-2009, 01:42 PM
  4. connection problem
    By subash in forum JDBC
    Replies: 5
    Last Post: 04-22-2008, 09:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •