[Ikvm-developers] No suitable driver found for jdbc:mysql
Brought to you by:
jfrijters
|
From: Colin C. <te...@gm...> - 2015-06-02 15:39:54
|
Hi,
I have written a java class to select data from mysql database, here is my
code:
import cli.System.Runtime.InteropServices.*;
import java.sql.*; // Use classes in java.sql package
// JDK 7 and above
@ClassInterfaceAttribute.Annotation(ClassInterfaceType.__Enum.AutoDual)
public class JdbcSelectTest
{
// Save as "JdbcSelectTest.java"
public static void main(String[] args)
{
JdbcSelectTest conn = new JdbcSelectTest();
System.out.println(conn.SelectPNR("1"));
}
public String SelectPNR(String inseq)
{
String pnr = "Begin|";
try (
// Step 1: Allocate a database "Connection"
object
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/raas_prod",
"root", "ibm2007"); // MySQL
// Step 2: Allocate a "Statement" object in the
Connection
Statement stmt = conn.createStatement();
) {
// Step 3: Execute a SQL SELECT query, the query
result
// is returned in a "ResultSet" object.
String strSelect = "SELECT pnr_num FROM
raas_prod.pnr_seg_hist order by rand() LIMIT 1;";
//System.out.println("The SQL query is: " +
strSelect); // Echo For debugging
//System.out.println();
ResultSet rset = stmt.executeQuery(strSelect);
// Step 4: Process the ResultSet by scrolling the
cursor forward via next().
// For each row, retrieve the contents of the
cells with getXxx(columnName).
//System.out.println("The records selected
are:");
int rowCount = 0;
while(rset.next()) { // Move the cursor to the
next row
pnr = rset.getString("pnr_num");
//System.out.println(pnr + ", " + action + ",
" + dep_airpt);
++rowCount;
}
//System.out.println("Total number of records = "
+ rowCount);
} catch(SQLException ex) {
ex.printStackTrace();
}
return inseq + " = " + pnr;
// Step 5: Close the resources - Done automatically
by try-with-resources
}
}
I manage to compile this with ikvmc to DLL and did the tlbexp. I can call
the function from Excel VBA, but it returns to me the "No suitable drive
found for jdbc:mysql." error whenever I call the function.
Please guide me if I have need to do something in the code, or add some
parameters when compiling the DLL, or I need to copy the
mysql-connector-java-x.x.xx-bin.jar file to some specific location?
Any help is appreciated.
Thanks.
Cheers,
Colin
|