java语法错误,将“}”插入到完整 MethodBody 中
importjava.sql.*;publicclassJDBCTest{publicstaticvoidmain(String[]args){//此错语法错误,将“}”...
import java.sql.*;
public class JDBCTest {
public static void main(String[] args)
{ //此错语法错误,将“}”插入到完整 MethodBody 中
static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=数据库的名字";
static final String USER = "你数据库的用户名";
static final String PWD = "密码";
public static Connection getConnection() {
Connection con = null;
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, USER,PWD);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
} 展开
public class JDBCTest {
public static void main(String[] args)
{ //此错语法错误,将“}”插入到完整 MethodBody 中
static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=数据库的名字";
static final String USER = "你数据库的用户名";
static final String PWD = "密码";
public static Connection getConnection() {
Connection con = null;
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, USER,PWD);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
} 展开
展开全部
这段代码是}不配对,你结尾再加一个},估计就可以了
追问
就是缺一个},但是加上还出错。不知怎么加。
追答
你试一下这样:
import java.sql.*;
public class JDBCTest {
static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=数据库的名字";
static final String USER = "你数据库的用户名";
static final String PWD = "密码";
public static void main(String[] args)
{
}
public static Connection getConnection() {
Connection con = null;
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, USER,PWD);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询