<%@ page import ="java.sql.*" %>
<h1>hello saurabh</h1>
<%
String s1 = request.getParameter("uname");
String s2="saurabh";
String driver ="com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3306/amber";
String userName = "root";
String password = "sameer0207";
Connection conn = null;
Statement st = null;
out.println(s2);
try {
out.println("Enterd in try");
Class.forName(driver);
out.println(driver);
conn = DriverManager.getConnection(url,userName,password);
out.println("Connected to the database");
String query="INSERT INTO quote VALUES (garima, 8588803860, 'tyagi619@gmail.com', 'kuchb bhi');";
st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
if(rs.next())
{out.println("success");
conn.close();}
else
{out.println("not success");}
}catch(Exception e){
System.out.println("Exception occured! "+e.getMessage()+" "+e.getStackTrace());
}
%>
对编程来说绝对是新手,想将值插入数据库(mysql),但不知道我在做什么错。 通过root密码sameer0207登录mysql,然后使用名为amber的数据库,使用tomcat服务器,我在tomcat上运行时正在部署Web应用程序,我可以看到在class.ForName之后没有执行任何操作,不知道为什么? 请帮助