简体   繁体   中英

problems writing code to database html

Im trying to write information to a database just using jsp pages but I keep running into this error;

information storage was unsuccessful java.sql.SQLException: Must specify port after ':' in connection string

This is the code that I have;

 <%@page import="java.sql.*" %> <%@page import="java.util.Date" %> <% Class.forName("com.mysql.jdbc.Driver"); %> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>Player Register</title> <link rel='stylesheet' href= 'styles.css'> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h2 align="center"> Register</h2> <form class="my_form" action="playerDisplay.jsp" method="POST"> <fieldset> <legend>Please Enter Your Details</legend> <h1 class="h1a">New Player</h1> <p> <label class="labela" for="login">Name:</label> <input type="text" name="Name" id="Name" value="Name"required> </p> <p> <label class="labela" for="login">Surname:</label> <input type="text" name="Surname" id="Surname" value="Surname"required> </p> <p> <label class="labela" for="login">PPS Number:</label> <input type="text" name="PPS_Number" id="PPS_Number" value="PPS_Number"required> </p> <p> <label class="labela" for="login">Grade:</label> <input type="text" name="Grade" id="Grade" value="Grade"required> </p> <p> <label class="labela" for="login">Email:</label> <input type="text" name="Email" id="Email" value="Email"required> </p> <p> <label class="labela" for="password">Password:</label> <input type="password" name="password" id="Password" value="123456"required> </p> <p> <input type="checkbox" name="mailingList" value="yes">Yes, add me to your mailing list<br> </p> <div style="text-align: center"> <input type="submit" name="submit"> <input type="reset" name="reset"> </div> </fieldset> </form> </body> </html> 

 <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.PreparedStatement"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <link href="CSS/styles.css" rel="stylesheet" type="text/css"/> <script src="js/libs/jquery/jquery.js"></script> <style> table, td, th { border: 1px solid black; } td { padding: 15px; } #optionalFieldset { display: none; } </style> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Your Space</title> <link rel='stylesheet' href= 'styles.css'> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> $(document).ready(function () { $("#optionalCheck").click(function () { $("#optionalFieldset").slideToggle("slow"); }); }); </script> </head> <body> <fieldset> <legend>Your Info</legend> <% String Name=request.getParameter("Name"); String Surname=request.getParameter("Surname"); String PPS_Number=request.getParameter("PPS_Number"); String Grade=request.getParameter("Grade"); String Email=request.getParameter("Email"); String Password=request.getParameter("Password"); try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=DriverManager.getConnection("jdbc:mysql://http://danu6.it.nuigalway.ie:3306/mydb1899/players", "mydb1899a", "mydb1899a"); PreparedStatement ps = conn.prepareStatement("INSERT INTO players(Name,Surname,PPS_Number,Grade,Email,Password) VALUES(?,?,?,?,?,?)"); ps.setString(1,Name); ps.setString(2,Surname); ps.setString(3,PPS_Number); ps.setString(4,Grade); ps.setString(5,Email); ps.setString(6,Password); ps.executeUpdate(); out.println("Your information was successfully stored in our database"); conn.close(); ps.close(); } catch(Exception e) { out.println("information storage was unsuccessful " + e); } %> </fieldset> <a href="index.html">Home</a> </body> </html> 

Is there any way that I can do it this way and if so is there a solution to the error I have?

jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]

That is the format for connection URLs. Does yours work with that?

I think you do not want the http:// in there, for a proper URL you would want either MySQL:// -OR- http:// not both.

I am guessing your proper string is going to be :

jdbc:mysql://danu6.it.nuigalway.ie:3306/mydb1899/players

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM