Jump to content
Sign in to follow this  
mk_gunnerz

Masalah Connect Dengan Database:not Suitable Driver

Recommended Posts

salam..saya de masalah nak connect dengan database.saya implement guna jdk1.6,mysql xamp,jdbc..masalahnya bila run,keluar not suitable driver found for jdbc..saya dah cba install jdbc driver n set classpath,tp tetap xberjaya.mohon bantuan..

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!");

}

}
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...