> I have been trying to make a java program read from
> my mysql database, but i am stuck on the part were it
> loads the drivers, any help?
>
What have you done? What problems are you having?
> Also, is there a way to encrypt my username and
> password for my database so that if some one
> decompiles my code they cannot see my real name or
> pass?
No.
well i haven't done much yet, i just put in this code my friend game me and called it in the main void and i get an error that says it cannot find "com.mysql.jdbc.Driver" so i tried to change it around, remove the quotes and replace it with others i have found but it always says it cannot find it. Its not a compiler error, just returns an error when i try to call the void sqlConnect or whatever...
public static void sqlConnect()
{
try {
Statement stmt;
//Register the JDBC driver for MySQL.
Class.forName("com.mysql.jdbc.Driver");
//Define URL of database server for
// database named mysql on the localhost
// with the default port number 3306.
String url =
"jdbc:mysql://localhost:3306/mysql";
//Get a connection to the database for a
// user named root with a blank password.
// This user is the default administrator
// having full privileges to do anything.
Connection con =
DriverManager.getConnection(
url,"root", "******");
//Display URL and connection information
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
//Get a Statement object
stmt = con.createStatement();
//Create the new database
stmt.executeUpdate(
"CREATE DATABASE JunkDB");
//Register a new user named auser on the
// database named JunkDB with a password
// drowssap enabling several different
// privileges.
stmt.executeUpdate(
"GRANT SELECT,INSERT,UPDATE,DELETE," +
"CREATE,DROP " +
"ON JunkDB.* TO 'auser'@'localhost' " +
"IDENTIFIED BY 'drowssap';");
con.close();
}catch( Exception e ) {
e.printStackTrace();
}
}
Message was edited by:
Hiaburi
if you are using netbeans for the developpement,
go to window > runtime,
and in the runtime window, right click on the database, add new ..., follow steps to add the new database and its drivers.
the major problem you encountered is that you have no mysql driver on the classpath.
elsewhere, I see no problem with the code
cheer
Hi,
Below the java program that check loading the mysql jdbc type 4 driver
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Driver;
public class MySqlReg {
public static void main(String[] args) {
try{
Class.forName("con.mysql.jdbc.Driver").newInstance();
System.out.print("Load MySql Driver Successfully");
}catch(Exception e){
System.out.print("Handle the Error Please");
}
}
}
for any more further query u may contact to
Vishnu Mohan
Agra-India
Phone - +919897214851
mail- mohan.vishnu@gmail.com