| |

VerySource

 Forgot password?
 Register
Search
View: 4192|Reply: 26

Novice help: java can access the contents of the table when connected with jdbc in java, why is the result not displayed

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 15:10:01
| Show all posts |Read mode
I can connect to the database in java, but it is not displayed in jsp? ? ?
Source program:
<% @ page contentType = "text / html; charset = GB2312"%>
<% @ page import = "java.sql. *"%>
<html>
<body> <FONT SIZE = 5>
<%
out.print ("<Table Border>");
out.print ("<TR>");
out.print ("<TH width = 100>" + "Student number");
out.print ("<TH width = 100>" + "Name");
out.print ("<TH width = 50>" + "math score");
out.print ("<TH width = 50>" + "English score");
out.print ("<TH width = 50>" + "Physical score");
out.print ("</ TR>");
try
{
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException e) {}
try
{
String url = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = pubs";
String user = "myair99";
String password = "19831228";
Connection con = DriverManager.getConnection (url, user, password);
Statement st = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery ("select * from students");
Ranch

while (rs.next ())
            {
                out.print ("<TD>" + rs.getString (1) + "</ TD>");
            Ranch
           }
rs.close ();
st.close ();
            con.close ();
        }
        catch (Exception err) {
           
        }
%>

</ body>
</ html>
After entering http: // localhost: 8080 / text.jsp
Can only display tables, but can't connect to the database? why?
It can be connected in java, and the contents of the students table have been displayed.
Thank you! !! !! ~
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-16 10:36:01
| Show all posts
Make sure your connection is correct and you can find the recordset,
Add <tr> </ tr> complete tags when outputting.
Such as:
out.print ("<tr> <TD>" + rs.getString (1) + "</ TD> </ tr>");
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-17 17:36:01
| Show all posts
I changed your opinion into the program, but still not connected, oh! ~
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-18 11:45:01
| Show all posts
catch (Exception err) {
           Print out err here, you ignore the exceptions, this is not right :)
        }
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-18 22:18:01
| Show all posts
driver jar package is placed under lib
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-30 00:27:01
| Show all posts
Should be out.print ("<TD>" + rs.getString (1) + "</ TD>"); there is a problem
I saw in a book that there were single quotes inside.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-31 11:15:01
| Show all posts
You ate the exception [color=#FF0000], (ClassNotFoundException e){} [/color]
    Please call the abnormal print. !
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-31 11:30:01
| Show all posts
There seems to be a problem with the host’s TR and TD
We need to pack TD into TR.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-31 11:45:01
| Show all posts
There is no problem with the program, it may be that the user and password of the library are assigned with more spaces
String user= "myair99";
String password= "19831228";
Or you can remove the try of the link library and see the error message
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-31 12:00:01
| Show all posts
It should be a connection problem.
绝对最强upstairs seems to be the key
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list