当我使用此代码时,我在连接到 mysql 数据库时遇到问题。我已经检查了端口号是 3128。所以没有问题。我检查了它,我认为问题出在
connection= DriverManager.getConnection("jdbc:mysql://localhost:3128/gcc","root", "root");
编译时没有错误。有人可以帮我吗?
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.sql.*;
//import java.net.*;
public class Main extends Applet implements ActionListener
{
TextArea tarea;
Button bsubmit;
public void init()
{
setBackground(new Color(0,0,0));
setForeground(Color.white);
Label l1=new Label("Write your code : ");
l1.setFont(new Font("lucida console",Font.PLAIN,25));
l1.setSize(200,30);
tarea=new TextArea();
tarea.setFont(new Font("lucida console",Font.PLAIN,18));
tarea.setForeground(new Color(0,0,0));
tarea.setSize(600,250);
bsubmit=new Button("Submit");
bsubmit.setFont(new Font("lucida console",Font.PLAIN,15));
bsubmit.setBackground(new Color(255,255,255));
bsubmit.setForeground(new Color(0,0,0));
bsubmit.setSize(100,30);
add(l1);
add(tarea);
add(bsubmit);
setLayout(null);
l1.setLocation(40,40);
tarea.setLocation(40,100);
bsubmit.setLocation(40,400);
bsubmit.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bsubmit)
{
Connection connection=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
connection= DriverManager.getConnection("jdbc:mysql://localhost:3128/gcc","root", "root");
Statement stmt = connection.createStatement();
stmt.executeUpdate("CREATE TABLE test2 (code VARCHAR(254))");
}
catch (Exception e) {}
}
}
}