mysql

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?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
[297 byte] By [Hiaburia] at [2007-11-27 7:06:25]
# 1

> 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.

cotton.ma at 2007-7-12 18:57:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

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

Hiaburia at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
ClassNotFound means that the driver is not in your classpath at runtime.
cotton.ma at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
oh, i think i read that some were but it wasn't worded like that, so what do i have to do to fix it? Best i can think is add the mysql folder to PATH in environmental variables?
Hiaburia at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
where is the classpath at runtime?
Genomsarena at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

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

ChackaPa at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
Get the mysql connector for java and add that to your classpath.
r035198xa at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

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

vishnu_uplca at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
@vishnu_uplc: how did you think that your "solution" solves the ClassNotFoundException?
BalusCa at 2007-7-12 18:57:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...