Jump to content


Photo

[Solved] Connecting to Database?


  • This topic is locked This topic is locked
12 replies to this topic

#1 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 19 February 2019 - 03:16 PM

Hi for my website I need to connect to a database. I have a MySQL database created and is on myphpadmin. In my code for my jsp I am using a connection string, Connection  con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lauraccc_fyp", "root", "*");, however when I try to run this jsp page on heliohost it is not connecting and I am getting a blank page. I am doing something wrong?

 



#2 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 10,153 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 19 February 2019 - 03:28 PM

 

("jdbc:mysql://localhost:3306/lauraccc_fyp", "root", "*");

 

 

You need to create a database user in cPanel, assign it to the DB, then specify that username and password in the connection string. Users don't have root access here unlike on a development box.


Please do not PM me for support. Posting on our forums lets all of us learn.

Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#3 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 19 February 2019 - 03:53 PM

I am still receiving a blank jsp page. My database is called lauraccc_fyp, my username is lauraccc_root and I have the correct passowrd. I am trying to insert into a table called lauraccc_fyp.register and the status is ok in cPanel

 

Connection  con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lauraccc_fyp", "lauraccc_root", "****");
           
        
          Statement stmt = con.createStatement();
          stmt.execute("insert into lauraccc_fyp.register (…...



#4 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 10,153 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 19 February 2019 - 04:30 PM

Krydos knows more about Java than most of us. Lets see if he knows why this doesn't work...


Please do not PM me for support. Posting on our forums lets all of us learn.

Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#5 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,831 posts
  • Gender:Male

Posted 19 February 2019 - 08:10 PM

Is this a .war or a .jsp?

#6 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 19 February 2019 - 08:30 PM

a .jsp



#7 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,831 posts
  • Gender:Male

Posted 19 February 2019 - 09:18 PM

When uploading .jsp files, etc. to your public_html folder the .jar files aren't loaded until Tomcat restarts. So likely what is happening is your site just doesn't have its mysql-connector loaded. I have restarted Tomcat. Are your mysql connections working now?

#8 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 26 February 2019 - 08:42 PM

Hi no my connections are still not working. Do I need to have uploaded a mySQL connector to cPanel as well?



#9 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 26 February 2019 - 09:04 PM

I am recieving; java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) error if that gives any indication?



#10 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,831 posts
  • Gender:Male

Posted 27 February 2019 - 12:10 AM

'root'@'localhost'

You don't have the root password for the server for obvious security reasons. Your mysql username will be something like lauraccc_root. You can create databases and database users through the mysql button in cpanel.

#11 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 28 February 2019 - 02:15 PM

Sorry for still bothering but I am still receiving this error. mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'lauraccc_root'@'localhost' to database 'lauraccc_fyp'



#12 lauraccc

lauraccc

    Rank I Member

  • Members
  • Pip
  • 17 posts

Posted 28 February 2019 - 04:26 PM

I have it working now, thank you for all your help. I will be donating 



#13 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,831 posts
  • Gender:Male

Posted 28 February 2019 - 09:27 PM

I'm glad you got it figured out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users