Home > Back-end >  JSP to mysql database SQL database serve, always turned out the problem by themselves
JSP to mysql database SQL database serve, always turned out the problem by themselves

Time:01-06

 

<% @ page contentType="text/HTML. Charset=GB2312 "% & gt;
<% @ page import="Java. SQL. *" % & gt;
<body bgcolor=cyan>
<% Connection con;
Statement sql;
The ResultSet rs;
Try {class.forname (". Com. Mysql. JDBC Driver ");
}
The catch (Exception e) {}
Try {String uri="JDBC: mysql://127.0.0.1/warehouse";
String user="root";
String password="";
Con=DriverManager. GetConnection (uri, user, password);
//can also be written as con=DriverManager. GetConnection (uri + "? User=root& Password=");
SQL=con. CreateStatement ();
Rs=SQL. ExecuteQuery (" SELECT * FROM the product ");
Out. Print (" & lt; The table border=2 & gt;" );
Out. Print (" & lt; Tr>" );
Out. Print (" & lt; Th width=100 & gt;" + "product number");
Out. Print (" & lt; Th width=100 & gt;" + "name");
Out. Print (" & lt; Th width=50 & gt;" + "production date");
Out. Print (" & lt; Th width=50 & gt;" + "price");
Out. Print (" & lt;/TR>" );
While (rs), next ()) {
Out. Print (" & lt; Tr>" );
Out. Print (" & lt; Td & gt;" + rs. Get string (1) + "& lt;/td>" );
Out. Print (" & lt; Td & gt;" + rs. Get string (2) + "& lt;/td>" );
Out. Print (" & lt; Td & gt;" + rs. GetDate (" madeTime ") + "& lt;/td>" );
Out. Print (" & lt; Td & gt;" + rs. GetFloat (" price ") + "& lt;/td>" );
Out. Print (" & lt;/tr>" );
}
Out. Print (" & lt;/table>" );
Con. The close ();
}
The catch (SQLException e) {
Out. Print (e);
}
%>

This code is how to use SQL database serve

CodePudding user response:

refer to the original poster zesmile response:
how the code to use SQL serve database


Change drivers were not

 
Class.forname (" com. Microsoft. JDBC. Essentially. SQLServerDriver ");

Connection conn=DriverManager. GetConnection (" JDBC: Microsoft: essentially://server1:1433 ", "user", "password");

  • Related