才开始学习javaWeb开发,但是这个数据库获取总是出问题。。。
jsp文件:
<%@ page import="main.test" contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
test t=new test();
String m=t.getPrice();
%>
<%=m%>
</body>
</html>
test.java:
public class test
{
private DatabaseMetaData dbMetaData=null;
private Connection conn=null;
public test()
{
this.getDatabaseMetaData();
}
private void getDatabaseMetaData()
{
try
{
if (dbMetaData == null)
{
Class.forName("com.mysql.jdbc.Driver"); //驱动程序名称 此处加载驱动程序
String url = "jdbc:mysql://localhost:3306/shoppractice";
String user = "root";
String psd = "970928";
conn = DriverManager.getConnection(url, user, psd);
}
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public String getPrice()
{
String selectSql="select goodPrice from tb_info where goodId='200102'";
String s=null;
try
{
Statement statement=conn.createStatement(); //创建Statement对象,用来执行SQL语句
ResultSet rs=statement.executeQuery(selectSql); //ResultSet类,用来存放获取的结果集
String price=null;
while(rs.next())
{ price=rs.getString("goodPrice"); }
s=price;
rs.close();
statement.close();
conn.close();
}catch(SQLException e)
{}
return s;
}
}
数据库:
运行之后出错:
500--Internal Server Error
自己新建的Java使用上面的test.java代码是可以获取到数据库的值的,所以jdbc桥应该是好的。
实在不知道自己哪里错了,求解答